adminforth 2.4.0-next.21 → 2.4.0-next.211

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 (192) hide show
  1. package/commands/callTsProxy.js +14 -4
  2. package/commands/cli.js +10 -3
  3. package/commands/createApp/templates/custom/tsconfig.json.hbs +2 -3
  4. package/commands/createApp/templates/index.ts.hbs +10 -2
  5. package/commands/createApp/templates/package.json.hbs +1 -1
  6. package/commands/createApp/utils.js +27 -2
  7. package/commands/createCustomComponent/configLoader.js +3 -0
  8. package/commands/createCustomComponent/main.js +1 -0
  9. package/commands/createCustomComponent/templates/customCrud/beforeActionButtons.vue.hbs +38 -0
  10. package/commands/createPlugin/templates/custom/tsconfig.json.hbs +2 -5
  11. package/commands/createPlugin/templates/package.json.hbs +1 -1
  12. package/dist/auth.d.ts +9 -1
  13. package/dist/auth.d.ts.map +1 -1
  14. package/dist/auth.js +15 -2
  15. package/dist/auth.js.map +1 -1
  16. package/dist/dataConnectors/baseConnector.d.ts.map +1 -1
  17. package/dist/dataConnectors/baseConnector.js +46 -15
  18. package/dist/dataConnectors/baseConnector.js.map +1 -1
  19. package/dist/dataConnectors/clickhouse.d.ts.map +1 -1
  20. package/dist/dataConnectors/clickhouse.js +15 -0
  21. package/dist/dataConnectors/clickhouse.js.map +1 -1
  22. package/dist/dataConnectors/mongo.d.ts.map +1 -1
  23. package/dist/dataConnectors/mongo.js +44 -15
  24. package/dist/dataConnectors/mongo.js.map +1 -1
  25. package/dist/dataConnectors/mysql.d.ts.map +1 -1
  26. package/dist/dataConnectors/mysql.js +11 -0
  27. package/dist/dataConnectors/mysql.js.map +1 -1
  28. package/dist/dataConnectors/postgres.d.ts.map +1 -1
  29. package/dist/dataConnectors/postgres.js +11 -0
  30. package/dist/dataConnectors/postgres.js.map +1 -1
  31. package/dist/dataConnectors/sqlite.d.ts.map +1 -1
  32. package/dist/dataConnectors/sqlite.js +11 -0
  33. package/dist/dataConnectors/sqlite.js.map +1 -1
  34. package/dist/index.d.ts +2 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +20 -9
  37. package/dist/index.js.map +1 -1
  38. package/dist/modules/codeInjector.d.ts +2 -0
  39. package/dist/modules/codeInjector.d.ts.map +1 -1
  40. package/dist/modules/codeInjector.js +52 -8
  41. package/dist/modules/codeInjector.js.map +1 -1
  42. package/dist/modules/configValidator.d.ts.map +1 -1
  43. package/dist/modules/configValidator.js +74 -7
  44. package/dist/modules/configValidator.js.map +1 -1
  45. package/dist/modules/restApi.d.ts.map +1 -1
  46. package/dist/modules/restApi.js +154 -26
  47. package/dist/modules/restApi.js.map +1 -1
  48. package/dist/modules/styles.d.ts +503 -13
  49. package/dist/modules/styles.d.ts.map +1 -1
  50. package/dist/modules/styles.js +559 -31
  51. package/dist/modules/styles.js.map +1 -1
  52. package/dist/modules/utils.d.ts +2 -0
  53. package/dist/modules/utils.d.ts.map +1 -1
  54. package/dist/modules/utils.js +16 -0
  55. package/dist/modules/utils.js.map +1 -1
  56. package/dist/servers/express.d.ts.map +1 -1
  57. package/dist/servers/express.js +14 -0
  58. package/dist/servers/express.js.map +1 -1
  59. package/dist/spa/index.html +1 -1
  60. package/dist/spa/package-lock.json +5 -4
  61. package/dist/spa/package.json +1 -1
  62. package/dist/spa/src/App.vue +54 -169
  63. package/dist/spa/src/adminforth.ts +42 -18
  64. package/dist/spa/src/afcl/BarChart.vue +2 -2
  65. package/dist/spa/src/afcl/Button.vue +6 -6
  66. package/dist/spa/src/afcl/ButtonGroup.vue +91 -0
  67. package/dist/spa/src/afcl/Card.vue +25 -0
  68. package/dist/spa/src/afcl/Checkbox.vue +21 -13
  69. package/dist/spa/src/afcl/CountryFlag.vue +4 -1
  70. package/dist/spa/src/{components/CustomDatePicker.vue → afcl/DatePicker.vue} +95 -9
  71. package/dist/spa/src/afcl/Dialog.vue +44 -27
  72. package/dist/spa/src/afcl/Dropzone.vue +12 -12
  73. package/dist/spa/src/afcl/Input.vue +6 -6
  74. package/dist/spa/src/afcl/JsonViewer.vue +25 -0
  75. package/dist/spa/src/afcl/LinkButton.vue +3 -3
  76. package/dist/spa/src/afcl/PieChart.vue +5 -5
  77. package/dist/spa/src/afcl/ProgressBar.vue +7 -7
  78. package/dist/spa/src/afcl/Select.vue +68 -34
  79. package/dist/spa/src/afcl/Skeleton.vue +6 -6
  80. package/dist/spa/src/afcl/Table.vue +213 -74
  81. package/dist/spa/src/afcl/Textarea.vue +31 -0
  82. package/dist/spa/src/afcl/Toggle.vue +32 -0
  83. package/dist/spa/src/afcl/Tooltip.vue +1 -2
  84. package/dist/spa/src/afcl/VerticalTabs.vue +16 -7
  85. package/dist/spa/src/afcl/index.ts +6 -3
  86. package/dist/spa/src/components/AcceptModal.vue +7 -7
  87. package/dist/spa/src/components/Breadcrumbs.vue +5 -5
  88. package/dist/spa/src/components/ColumnValueInput.vue +38 -18
  89. package/dist/spa/src/components/ColumnValueInputWrapper.vue +4 -3
  90. package/dist/spa/src/components/CustomDateRangePicker.vue +9 -8
  91. package/dist/spa/src/components/CustomRangePicker.vue +37 -8
  92. package/dist/spa/src/components/ErrorMessage.vue +21 -0
  93. package/dist/spa/src/components/Filters.vue +85 -39
  94. package/dist/spa/src/components/GroupsTable.vue +9 -8
  95. package/dist/spa/src/components/MenuLink.vue +90 -23
  96. package/dist/spa/src/components/ResourceForm.vue +94 -51
  97. package/dist/spa/src/components/ResourceListTable.vue +78 -80
  98. package/dist/spa/src/components/ResourceListTableVirtual.vue +71 -73
  99. package/dist/spa/src/components/ShowTable.vue +17 -12
  100. package/dist/spa/src/components/Sidebar.vue +448 -0
  101. package/dist/spa/src/components/SingleSkeletLoader.vue +6 -6
  102. package/dist/spa/src/components/SkeleteLoader.vue +3 -3
  103. package/dist/spa/src/components/ThreeDotsMenu.vue +73 -14
  104. package/dist/spa/src/components/Toast.vue +27 -9
  105. package/dist/spa/src/components/UserMenuSettingsButton.vue +70 -0
  106. package/dist/spa/src/components/ValueRenderer.vue +43 -16
  107. package/dist/spa/src/controls/BoolToggle.vue +34 -0
  108. package/dist/spa/src/i18n.ts +1 -1
  109. package/dist/spa/src/renderers/CompactField.vue +1 -1
  110. package/dist/spa/src/renderers/CompactUUID.vue +1 -1
  111. package/dist/spa/src/router/index.ts +8 -0
  112. package/dist/spa/src/shims-vue.d.ts +5 -0
  113. package/dist/spa/src/spa_types/core.ts +13 -1
  114. package/dist/spa/src/stores/core.ts +1 -1
  115. package/dist/spa/src/stores/filters.ts +29 -2
  116. package/dist/spa/src/stores/modal.ts +6 -1
  117. package/dist/spa/src/stores/toast.ts +22 -3
  118. package/dist/spa/src/types/Back.ts +137 -22
  119. package/dist/spa/src/types/Common.ts +67 -32
  120. package/dist/spa/src/types/FrontendAPI.ts +31 -5
  121. package/dist/spa/src/types/adapters/CaptchaAdapter.ts +34 -0
  122. package/dist/spa/src/types/adapters/CompletionAdapter.ts +25 -0
  123. package/dist/spa/src/types/adapters/EmailAdapter.ts +27 -0
  124. package/dist/spa/src/types/adapters/ImageGenerationAdapter.ts +50 -0
  125. package/dist/spa/src/types/adapters/ImageVisionAdapter.ts +30 -0
  126. package/dist/spa/src/types/adapters/KeyValueAdapter.ts +16 -0
  127. package/dist/spa/src/types/adapters/OAuth2Adapter.ts +34 -0
  128. package/dist/spa/src/types/adapters/StorageAdapter.ts +73 -0
  129. package/dist/spa/src/types/adapters/index.ts +8 -0
  130. package/dist/spa/src/utils.ts +219 -8
  131. package/dist/spa/src/views/CreateView.vue +18 -19
  132. package/dist/spa/src/views/EditView.vue +25 -19
  133. package/dist/spa/src/views/ListView.vue +139 -86
  134. package/dist/spa/src/views/LoginView.vue +31 -37
  135. package/dist/spa/src/views/ResourceParent.vue +2 -2
  136. package/dist/spa/src/views/SettingsView.vue +121 -0
  137. package/dist/spa/src/views/ShowView.vue +59 -39
  138. package/dist/spa/src/websocket.ts +6 -1
  139. package/dist/spa/tsconfig.app.json +1 -1
  140. package/dist/spa/vite.config.ts +45 -2
  141. package/dist/types/Back.d.ts +115 -14
  142. package/dist/types/Back.d.ts.map +1 -1
  143. package/dist/types/Back.js +15 -0
  144. package/dist/types/Back.js.map +1 -1
  145. package/dist/types/Common.d.ts +59 -29
  146. package/dist/types/Common.d.ts.map +1 -1
  147. package/dist/types/Common.js.map +1 -1
  148. package/dist/types/FrontendAPI.d.ts +31 -3
  149. package/dist/types/FrontendAPI.d.ts.map +1 -1
  150. package/dist/types/FrontendAPI.js.map +1 -1
  151. package/dist/types/adapters/CaptchaAdapter.d.ts +30 -0
  152. package/dist/types/adapters/CaptchaAdapter.d.ts.map +1 -0
  153. package/dist/types/adapters/CaptchaAdapter.js +5 -0
  154. package/dist/types/adapters/CaptchaAdapter.js.map +1 -0
  155. package/dist/types/adapters/CompletionAdapter.d.ts +20 -0
  156. package/dist/types/adapters/CompletionAdapter.d.ts.map +1 -0
  157. package/dist/types/adapters/CompletionAdapter.js +2 -0
  158. package/dist/types/adapters/CompletionAdapter.js.map +1 -0
  159. package/dist/types/adapters/EmailAdapter.d.ts +20 -0
  160. package/dist/types/adapters/EmailAdapter.d.ts.map +1 -0
  161. package/dist/types/adapters/EmailAdapter.js +2 -0
  162. package/dist/types/adapters/EmailAdapter.js.map +1 -0
  163. package/dist/types/adapters/ImageGenerationAdapter.d.ts +37 -0
  164. package/dist/types/adapters/ImageGenerationAdapter.d.ts.map +1 -0
  165. package/dist/types/adapters/ImageGenerationAdapter.js +2 -0
  166. package/dist/types/adapters/ImageGenerationAdapter.js.map +1 -0
  167. package/dist/types/adapters/ImageVisionAdapter.d.ts +25 -0
  168. package/dist/types/adapters/ImageVisionAdapter.d.ts.map +1 -0
  169. package/dist/types/adapters/ImageVisionAdapter.js +2 -0
  170. package/dist/types/adapters/ImageVisionAdapter.js.map +1 -0
  171. package/dist/types/adapters/KeyValueAdapter.d.ts +10 -0
  172. package/dist/types/adapters/KeyValueAdapter.d.ts.map +1 -0
  173. package/dist/types/adapters/KeyValueAdapter.js +2 -0
  174. package/dist/types/adapters/KeyValueAdapter.js.map +1 -0
  175. package/dist/types/adapters/OAuth2Adapter.d.ts +32 -0
  176. package/dist/types/adapters/OAuth2Adapter.d.ts.map +1 -0
  177. package/dist/types/adapters/OAuth2Adapter.js +2 -0
  178. package/dist/types/adapters/OAuth2Adapter.js.map +1 -0
  179. package/dist/types/adapters/StorageAdapter.d.ts +63 -0
  180. package/dist/types/adapters/StorageAdapter.d.ts.map +1 -0
  181. package/dist/types/adapters/StorageAdapter.js +2 -0
  182. package/dist/types/adapters/StorageAdapter.js.map +1 -0
  183. package/dist/types/adapters/index.d.ts +9 -0
  184. package/dist/types/adapters/index.d.ts.map +1 -0
  185. package/dist/types/adapters/index.js +2 -0
  186. package/dist/types/adapters/index.js.map +1 -0
  187. package/package.json +3 -2
  188. package/dist/spa/src/types/Adapters.ts +0 -213
  189. package/dist/types/Adapters.d.ts +0 -168
  190. package/dist/types/Adapters.d.ts.map +0 -1
  191. package/dist/types/Adapters.js +0 -2
  192. package/dist/types/Adapters.js.map +0 -1
@@ -0,0 +1,50 @@
1
+ export interface ImageGenerationAdapter {
2
+
3
+ /**
4
+ * This method is called to validate the configuration of the adapter
5
+ * and should throw a clear user-readbale error if the configuration is invalid.
6
+ */
7
+ validate(): void;
8
+
9
+ /**
10
+ * Return max number of images which model can generate in one request
11
+ */
12
+ outputImagesMaxCountSupported(): number;
13
+
14
+ /**
15
+ * Return the list of supported dimensions in format ["100x500", "200x200"]
16
+ */
17
+ outputDimensionsSupported(): string[];
18
+
19
+ /**
20
+ * Input file extension supported
21
+ */
22
+ inputFileExtensionSupported(): string[];
23
+
24
+ /**
25
+ * This method should generate an image based on the provided prompt and input files.
26
+ * @param prompt - The prompt to generate the image
27
+ * @param inputFiles - An array of input file paths (optional)
28
+ * @param n - The number of images to generate (default is 1)
29
+ * @param size - The size of the generated image (default is the lowest dimension supported)
30
+ * @returns A promise that resolves to an object containing the generated image URLs and any error message
31
+ */
32
+ generate({
33
+ prompt,
34
+ inputFiles,
35
+ n,
36
+ size,
37
+ }: {
38
+ prompt: string,
39
+ inputFiles: string[],
40
+
41
+ // default = lowest dimension supported
42
+ size?: string,
43
+
44
+ // one by default
45
+ n?: number
46
+ }): Promise<{
47
+ imageURLs?: string[];
48
+ error?: string;
49
+ }>;
50
+ }
@@ -0,0 +1,30 @@
1
+ export interface ImageVisionAdapter {
2
+
3
+ /**
4
+ * This method is called to validate the configuration of the adapter
5
+ * and should throw a clear user-readable error if the configuration is invalid.
6
+ */
7
+ validate(): void;
8
+
9
+ /**
10
+ * Input file extension supported
11
+ */
12
+ inputFileExtensionSupported(): string[];
13
+
14
+ /**
15
+ * This method should generate an image based on the provided prompt and input files.
16
+ * @param prompt - The prompt to generate the image
17
+ * @param inputFileUrls - An array of input file paths (optional)
18
+ * @returns A promise that resolves to an object containing the generated image and any error message
19
+ */
20
+ generate({
21
+ prompt,
22
+ inputFileUrls,
23
+ }: {
24
+ prompt: string,
25
+ inputFileUrls: string[],
26
+ }): Promise<{
27
+ response: string;
28
+ error?: string;
29
+ }>;
30
+ }
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * Might have implementations like RAM, Redis, Memcached,
4
+ *
5
+ */
6
+ export interface KeyValueAdapter {
7
+
8
+ get(key: string): Promise<string | null>;
9
+
10
+ set(key: string, value: string, expiresInSeconds?: number): Promise<void>;
11
+
12
+ delete(key: string): Promise<void>;
13
+
14
+ }
15
+
16
+
@@ -0,0 +1,34 @@
1
+
2
+ /**
3
+ * This interface is used to implement OAuth2 authentication adapters.
4
+ */
5
+ export interface OAuth2Adapter {
6
+ /**
7
+ * This method should return navigatable URL to the OAuth2 provider authentication page.
8
+ */
9
+ getAuthUrl(): string;
10
+
11
+ /**
12
+ * This method should return the token from the OAuth2 provider using the provided code and redirect URI.
13
+ * @param code - The authorization code received from the OAuth2 provider
14
+ * @param redirect_uri - The redirect URI used in the authentication request
15
+ * @returns A promise that resolves to an object containing the email address of the authenticated user
16
+ */
17
+ getTokenFromCode(code: string, redirect_uri: string): Promise<{ email: string }>;
18
+
19
+ /**
20
+ * This method should return text (content) of SVG icon which will be used in the UI.
21
+ * Use official SVG icons with simplest possible conent, omit icons which have base64 encoded raster images inside.
22
+ */
23
+ getIcon(): string;
24
+
25
+ /**
26
+ * This method should return the text to be displayed on the button in the UI
27
+ */
28
+ getButtonText?(): string;
29
+
30
+ /**
31
+ * This method should return the name of the adapter
32
+ */
33
+ getName?(): string;
34
+ }
@@ -0,0 +1,73 @@
1
+
2
+ /**
3
+ * Each storage adapter should support two ways of storing files:
4
+ * - publically (public URL) - the file can be accessed by anyone by HTTP GET / HEAD request with plain URL
5
+ * - privately (presigned URL) - the file can be accessed by anyone by HTTP GET / HEAD request only with presigned URLs, limited by expiration time
6
+ *
7
+ */
8
+ export interface StorageAdapter {
9
+ /**
10
+ * This method should return the presigned URL for the given key capable of upload (adapter user will call PUT multipart form data to this URL within expiresIn seconds after link generation).
11
+ * By default file which will be uploaded on PUT should be marked for deletion. So if during 24h it is not marked for not deletion, it adapter should delete it forever.
12
+ * The PUT method should fail if the file already exists.
13
+ *
14
+ * Adapter user will always pass next parameters to the method:
15
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
16
+ * @param expiresIn - The expiration time in seconds for the presigned URL
17
+ * @param contentType - The content type of the file to be uploaded, e.g. "image/png"
18
+ *
19
+ * @returns A promise that resolves to an object containing the upload URL and any extra parameters which should be sent with PUT multipart form data
20
+ */
21
+ getUploadSignedUrl(key: string, contentType: string, expiresIn?: number): Promise<{
22
+ uploadUrl: string;
23
+ uploadExtraParams?: Record<string, string>;
24
+ }>;
25
+
26
+ /**
27
+ * This method should return the URL for the given key capable of download (200 GET request with response body or 200 HEAD request without response body).
28
+ * If adapter configured to store objects publically, this method should return the public URL of the file.
29
+ * If adapter configured to no allow public storing of images, this method should return the presigned URL for the file.
30
+ *
31
+ * @param key - The key of the file to be downloaded e.g. "uploads/file.txt"
32
+ * @param expiresIn - The expiration time in seconds for the presigned URL
33
+ */
34
+ getDownloadUrl(key: string, expiresIn?: number): Promise<string>;
35
+
36
+ /**
37
+ * This method should mark the file for deletion.
38
+ * If file is marked for delation and exists more then 24h (since creation date) it should be deleted.
39
+ * This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
40
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
41
+ */
42
+ markKeyForDeletation(key: string): Promise<void>;
43
+
44
+
45
+ /**
46
+ * This method should mark the file to not be deleted.
47
+ * This method should be used to cancel the deletion of the file if it was marked for deletion.
48
+ * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
49
+ */
50
+ markKeyForNotDeletation(key: string): Promise<void>;
51
+
52
+
53
+ /**
54
+ * This method can start needed schedullers, cron jobs, etc. to clean up the storage.
55
+ * @param adapterUserUniqueRepresentation - The unique representation of the plugin instance which
56
+ * wil use this adapter. Might be handy if you need to distinguish between different instances of the same adapter.
57
+ */
58
+ setupLifecycle(adapterUserUniqueRepresentation: string): Promise<void>;
59
+
60
+ /**
61
+ * If adapter is configured to publically, this method should return true.
62
+ */
63
+ objectCanBeAccesedPublicly(): Promise<boolean>;
64
+
65
+ /**
66
+ * This method should return the key as a data URL (base64 encoded string).
67
+ * @param key - The key of the file to be converted to a data URL
68
+ * @returns A promise that resolves to a string containing the data URL
69
+ */
70
+ getKeyAsDataURL(key: string): Promise<string>;
71
+ }
72
+
73
+
@@ -0,0 +1,8 @@
1
+ export type { EmailAdapter } from './EmailAdapter.js';
2
+ export type { CompletionAdapter } from './CompletionAdapter.js';
3
+ export type { ImageGenerationAdapter } from './ImageGenerationAdapter.js';
4
+ export type { KeyValueAdapter } from './KeyValueAdapter.js';
5
+ export type { ImageVisionAdapter } from './ImageVisionAdapter.js';
6
+ export type { OAuth2Adapter } from './OAuth2Adapter.js';
7
+ export type { StorageAdapter } from './StorageAdapter.js';
8
+ export type { CaptchaAdapter } from './CaptchaAdapter.js';
@@ -1,14 +1,17 @@
1
1
  import { onMounted, ref, resolveComponent } from 'vue';
2
2
  import type { CoreConfig } from './spa_types/core';
3
- import type { ValidationObject } from './types/AdminForthConfig';
3
+ import type { ValidationObject } from './types/Common.js';
4
4
  import router from "./router";
5
5
  import { useCoreStore } from './stores/core';
6
6
  import { useUserStore } from './stores/user';
7
7
  import { Dropdown } from 'flowbite';
8
8
  import adminforth from './adminforth';
9
9
  import sanitizeHtml from 'sanitize-html'
10
+ import debounce from 'debounce';
10
11
 
11
12
  const LS_LANG_KEY = `afLanguage`;
13
+ const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
14
+ const ITEMS_PER_PAGE_LIMIT = 100;
12
15
 
13
16
  export async function callApi({path, method, body=undefined}: {
14
17
  path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
@@ -27,6 +30,7 @@ export async function callApi({path, method, body=undefined}: {
27
30
  const r = await fetch(fullPath, options);
28
31
  if (r.status == 401 ) {
29
32
  useUserStore().unauthorize();
33
+ useCoreStore().resetAdminUser();
30
34
  await router.push({ name: 'login' });
31
35
  return null;
32
36
  }
@@ -46,7 +50,7 @@ export async function callApi({path, method, body=undefined}: {
46
50
 
47
51
  export async function callAdminForthApi({ path, method, body=undefined, headers=undefined }: {
48
52
  path: string,
49
- method: 'GET' | 'POST' | 'PUT' | 'DELETE',
53
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',
50
54
  body?: any,
51
55
  headers?: Record<string, string>
52
56
  }): Promise<any> {
@@ -92,13 +96,14 @@ export const loadFile = (file: string) => {
92
96
  }
93
97
 
94
98
  export function checkEmptyValues(value: any, viewType: 'show' | 'list' ) {
95
- const config: CoreConfig | {} = useCoreStore().config;
99
+ const config: CoreConfig | {} | null = useCoreStore().config;
96
100
  let emptyFieldPlaceholder = '';
97
- if (config.emptyFieldPlaceholder) {
98
- if(typeof config.emptyFieldPlaceholder === 'string') {
99
- emptyFieldPlaceholder = config.emptyFieldPlaceholder;
101
+ if (config && 'emptyFieldPlaceholder' in config) {
102
+ const efp = (config as CoreConfig).emptyFieldPlaceholder;
103
+ if(typeof efp === 'string') {
104
+ emptyFieldPlaceholder = efp;
100
105
  } else {
101
- emptyFieldPlaceholder = config.emptyFieldPlaceholder?.[viewType] || '';
106
+ emptyFieldPlaceholder = efp?.[viewType] || '';
102
107
  }
103
108
  if (value === null || value === undefined || value === '') {
104
109
  return emptyFieldPlaceholder;
@@ -179,7 +184,7 @@ export function verySimpleHash(str: string): string {
179
184
  return `${str.split('').reduce((a, b)=>{a=((a<<5)-a)+b.charCodeAt(0);return a&a},0)}`;
180
185
  }
181
186
 
182
- export function humanifySize(size) {
187
+ export function humanifySize(size: number) {
183
188
  if (!size) {
184
189
  return '';
185
190
  }
@@ -208,4 +213,210 @@ export function protectAgainstXSS(value: string) {
208
213
  'img': [ 'src', 'srcset', 'alt', 'title', 'width', 'height', 'loading' ]
209
214
  }
210
215
  });
216
+ }
217
+
218
+ export function isPolymorphicColumn(column: any): boolean {
219
+ return !!(column.foreignResource?.polymorphicResources && column.foreignResource.polymorphicResources.length > 0);
220
+ }
221
+
222
+ export function handleForeignResourcePagination(
223
+ column: any,
224
+ items: any[],
225
+ emptyResultsCount: number = 0,
226
+ isSearching: boolean = false
227
+ ): { hasMore: boolean; emptyResultsCount: number } {
228
+ const isPolymorphic = isPolymorphicColumn(column);
229
+
230
+ if (isPolymorphic) {
231
+ if (isSearching) {
232
+ return {
233
+ hasMore: items.length > 0,
234
+ emptyResultsCount: 0
235
+ };
236
+ } else {
237
+ if (items.length === 0) {
238
+ const newEmptyCount = emptyResultsCount + 1;
239
+ return {
240
+ hasMore: newEmptyCount < MAX_CONSECUTIVE_EMPTY_RESULTS, // Stop loading after 2 consecutive empty results
241
+ emptyResultsCount: newEmptyCount
242
+ };
243
+ } else {
244
+ return {
245
+ hasMore: true,
246
+ emptyResultsCount: 0
247
+ };
248
+ }
249
+ }
250
+ } else {
251
+ return {
252
+ hasMore: items.length === ITEMS_PER_PAGE_LIMIT,
253
+ emptyResultsCount: 0
254
+ };
255
+ }
256
+ }
257
+
258
+ export async function loadMoreForeignOptions({
259
+ columnName,
260
+ searchTerm = '',
261
+ columns,
262
+ resourceId,
263
+ columnOptions,
264
+ columnLoadingState,
265
+ columnOffsets,
266
+ columnEmptyResultsCount
267
+ }: {
268
+ columnName: string;
269
+ searchTerm?: string;
270
+ columns: any[];
271
+ resourceId: string;
272
+ columnOptions: any;
273
+ columnLoadingState: any;
274
+ columnOffsets: any;
275
+ columnEmptyResultsCount: any;
276
+ }) {
277
+ const column = columns?.find(c => c.name === columnName);
278
+ if (!column || !column.foreignResource) return;
279
+
280
+ const state = columnLoadingState[columnName];
281
+ if (state.loading || !state.hasMore) return;
282
+
283
+ state.loading = true;
284
+
285
+ try {
286
+ const list = await callAdminForthApi({
287
+ method: 'POST',
288
+ path: `/get_resource_foreign_data`,
289
+ body: {
290
+ resourceId,
291
+ column: columnName,
292
+ limit: 100,
293
+ offset: columnOffsets[columnName],
294
+ search: searchTerm,
295
+ },
296
+ });
297
+
298
+ if (!list || !Array.isArray(list.items)) {
299
+ console.warn(`Unexpected API response for column ${columnName}:`, list);
300
+ state.hasMore = false;
301
+ return;
302
+ }
303
+
304
+ if (!columnOptions.value) {
305
+ columnOptions.value = {};
306
+ }
307
+ if (!columnOptions.value[columnName]) {
308
+ columnOptions.value[columnName] = [];
309
+ }
310
+ columnOptions.value[columnName].push(...list.items);
311
+
312
+ columnOffsets[columnName] += 100;
313
+
314
+ const paginationResult = handleForeignResourcePagination(
315
+ column,
316
+ list.items,
317
+ columnEmptyResultsCount[columnName] || 0,
318
+ false // not searching
319
+ );
320
+
321
+ columnEmptyResultsCount[columnName] = paginationResult.emptyResultsCount;
322
+ state.hasMore = paginationResult.hasMore;
323
+
324
+ } catch (error) {
325
+ console.error('Error loading more options:', error);
326
+ } finally {
327
+ state.loading = false;
328
+ }
329
+ }
330
+
331
+ export async function searchForeignOptions({
332
+ columnName,
333
+ searchTerm,
334
+ columns,
335
+ resourceId,
336
+ columnOptions,
337
+ columnLoadingState,
338
+ columnOffsets,
339
+ columnEmptyResultsCount
340
+ }: {
341
+ columnName: string;
342
+ searchTerm: string;
343
+ columns: any[];
344
+ resourceId: string;
345
+ columnOptions: any;
346
+ columnLoadingState: any;
347
+ columnOffsets: any;
348
+ columnEmptyResultsCount: any;
349
+ }) {
350
+ const column = columns?.find(c => c.name === columnName);
351
+
352
+ if (!column || !column.foreignResource || !column.foreignResource.searchableFields) {
353
+ return;
354
+ }
355
+
356
+ const state = columnLoadingState[columnName];
357
+ if (state.loading) return;
358
+
359
+ state.loading = true;
360
+
361
+ try {
362
+ const list = await callAdminForthApi({
363
+ method: 'POST',
364
+ path: `/get_resource_foreign_data`,
365
+ body: {
366
+ resourceId,
367
+ column: columnName,
368
+ limit: 100,
369
+ offset: 0,
370
+ search: searchTerm,
371
+ },
372
+ });
373
+
374
+ if (!list || !Array.isArray(list.items)) {
375
+ console.warn(`Unexpected API response for column ${columnName}:`, list);
376
+ state.hasMore = false;
377
+ return;
378
+ }
379
+
380
+ if (!columnOptions.value) {
381
+ columnOptions.value = {};
382
+ }
383
+ columnOptions.value[columnName] = list.items;
384
+ columnOffsets[columnName] = 100;
385
+
386
+ const paginationResult = handleForeignResourcePagination(
387
+ column,
388
+ list.items,
389
+ columnEmptyResultsCount[columnName] || 0,
390
+ true // is searching
391
+ );
392
+
393
+ columnEmptyResultsCount[columnName] = paginationResult.emptyResultsCount;
394
+ state.hasMore = paginationResult.hasMore;
395
+
396
+ } catch (error) {
397
+ console.error('Error searching options:', error);
398
+ } finally {
399
+ state.loading = false;
400
+ }
401
+ }
402
+
403
+ export function createSearchInputHandlers(
404
+ columns: any[],
405
+ searchFunction: (columnName: string, searchTerm: string) => void,
406
+ getDebounceMs?: (column: any) => number
407
+ ) {
408
+ if (!columns) return {};
409
+
410
+ return columns.reduce((acc, c) => {
411
+ if (c.foreignResource && c.foreignResource.searchableFields) {
412
+ const debounceMs = getDebounceMs ? getDebounceMs(c) : 300;
413
+ return {
414
+ ...acc,
415
+ [c.name]: debounce((searchTerm: string) => {
416
+ searchFunction(c.name, searchTerm);
417
+ }, debounceMs),
418
+ };
419
+ }
420
+ return acc;
421
+ }, {} as Record<string, (searchTerm: string) => void>);
211
422
  }
@@ -4,7 +4,7 @@
4
4
  <component
5
5
  v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.beforeBreadcrumbs || []"
6
6
  :is="getCustomComponent(c)"
7
- :meta="c.meta"
7
+ :meta="(c as AdminForthComponentDeclarationFull).meta"
8
8
  :record="coreStore.record"
9
9
  :resource="coreStore.resource"
10
10
  :adminUser="coreStore.adminUser"
@@ -13,25 +13,25 @@
13
13
  <BreadcrumbsWithButtons>
14
14
  <!-- save and cancle -->
15
15
  <button @click="$router.back()"
16
- class="flex items-center py-1 px-3 me-2 text-sm font-medium rounded-default text-gray-900 focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
16
+ class="af-cancel-button flex items-center py-1 px-3 me-2 text-sm font-medium rounded-default text-lightCreateViewButtonText focus:outline-none bg-lightCreateViewButtonBackground rounded border border-lightCreateViewButtonBorder hover:bg-lightCreateViewButtonBackgroundHover hover:text-lightCreateViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightCreateViewButtonFocusRing dark:focus:ring-darkCreateViewButtonFocusRing dark:bg-darkCreateViewButtonBackground dark:text-darkCreateViewButtonText dark:border-darkCreateViewButtonBorder dark:hover:text-darkCreateViewButtonTextHover dark:hover:bg-darkCreateViewButtonBackgroundHover"
17
17
  >
18
18
  {{ $t('Cancel') }}
19
19
  </button>
20
20
 
21
21
  <button
22
22
  @click="saveRecord"
23
- class="flex items-center py-1 px-3 text-sm font-medium rounded-default text-red-600 focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-red-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-red-500 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
23
+ class="af-save-button flex items-center py-1 px-3 text-sm font-medium rounded-default text-lightCreateViewSaveButtonText focus:outline-none bg-lightCreateViewButtonBackground rounded border border-lightCreateViewButtonBorder hover:bg-lightCreateViewButtonBackgroundHover hover:text-lightCreateViewSaveButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightCreateViewButtonFocusRing dark:focus:ring-darkCreateViewButtonFocusRing dark:bg-darkCreateViewButtonBackground dark:text-darkCreateViewSaveButtonText dark:border-darkCreateViewButtonBorder dark:hover:text-darkCreateViewSaveButtonTextHover dark:hover:bg-darkCreateViewButtonBackgroundHover disabled:opacity-50 gap-1"
24
24
  :disabled="saving || (validating && !isValid)"
25
25
  >
26
26
  <svg v-if="saving"
27
- aria-hidden="true" class="w-4 h-4 mr-1 text-gray-200 animate-spin dark:text-gray-600 fill-red-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
27
+ aria-hidden="true" class="w-4 h-4 mr-1 text-gray-200 animate-spin dark:text-gray-600 fill-lightCreateViewSaveButtonText" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
28
28
 
29
- <IconFloppyDiskSolid v-else class="w-4 h-4 mr-1" />
29
+ <IconFloppyDiskSolid v-else class="w-4 h-4" />
30
30
  {{ $t('Save') }}
31
31
  </button>
32
32
 
33
33
  <ThreeDotsMenu
34
- :threeDotsDropdownItems="coreStore.resourceOptions?.pageInjections?.create?.threeDotsDropdownItems"
34
+ :threeDotsDropdownItems="(coreStore.resourceOptions?.pageInjections?.create?.threeDotsDropdownItems as [])"
35
35
  ></ThreeDotsMenu>
36
36
 
37
37
  </BreadcrumbsWithButtons>
@@ -39,7 +39,7 @@
39
39
  <component
40
40
  v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.afterBreadcrumbs || []"
41
41
  :is="getCustomComponent(c)"
42
- :meta="c.meta"
42
+ :meta="(c as AdminForthComponentDeclarationFull).meta"
43
43
  :record="coreStore.record"
44
44
  :resource="coreStore.resource"
45
45
  :adminUser="coreStore.adminUser"
@@ -51,7 +51,7 @@
51
51
  <ResourceForm
52
52
  v-else
53
53
  :record="record"
54
- :resource="coreStore.resource"
54
+ :resource="coreStore.resource!"
55
55
  @update:record="onUpdateRecord"
56
56
  @update:isValid="isValid = $event"
57
57
  :validating="validating"
@@ -63,7 +63,7 @@
63
63
  <component
64
64
  v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.bottom || []"
65
65
  :is="getCustomComponent(c)"
66
- :meta="c.meta"
66
+ :meta="(c as AdminForthComponentDeclarationFull).meta"
67
67
  :record="coreStore.record"
68
68
  :resource="coreStore.resource"
69
69
  :adminUser="coreStore.adminUser"
@@ -88,6 +88,7 @@ import { showErrorTost } from '@/composables/useFrontendApi';
88
88
  import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
89
89
  import adminforth from '@/adminforth';
90
90
  import { useI18n } from 'vue-i18n';
91
+ import { type AdminForthComponentDeclarationFull } from '@/types/Common.js';
91
92
 
92
93
  const isValid = ref(false);
93
94
  const validating = ref(false);
@@ -109,36 +110,34 @@ const initialValues = ref({});
109
110
  const readonlyColumns = ref([]);
110
111
 
111
112
 
112
- async function onUpdateRecord(newRecord) {
113
- console.log('newRecord', newRecord);
113
+ async function onUpdateRecord(newRecord: any) {
114
114
  record.value = newRecord;
115
115
  }
116
116
 
117
117
  onMounted(async () => {
118
118
  loading.value = true;
119
119
  await coreStore.fetchResourceFull({
120
- resourceId: route.params.resourceId
120
+ resourceId: route.params.resourceId as string
121
121
  });
122
- initialValues.value = (coreStore.resource?.columns || []).reduce((acc, column) => {
122
+ initialValues.value = (coreStore.resource?.columns || []).reduce<Record<string, unknown>>((acc, column) => {
123
123
  if (column.suggestOnCreate !== undefined) {
124
124
  acc[column.name] = column.suggestOnCreate;
125
125
  }
126
126
  return acc;
127
127
  }, {});
128
128
  if (route.query.values) {
129
- initialValues.value = { ...initialValues.value, ...JSON.parse(decodeURIComponent(route.query.values)) };
129
+ initialValues.value = { ...initialValues.value, ...JSON.parse(decodeURIComponent(route.query.values as string)) };
130
130
  }
131
131
  if (route.query.readonlyColumns) {
132
- readonlyColumns.value = JSON.parse(decodeURIComponent(route.query.readonlyColumns));
132
+ readonlyColumns.value = JSON.parse(decodeURIComponent(route.query.readonlyColumns as string));
133
133
  }
134
134
  record.value = initialValues.value;
135
135
  loading.value = false;
136
- checkAcessByAllowedActions(coreStore.resourceOptions.allowedActions,'create');
136
+ checkAcessByAllowedActions(coreStore.resourceOptions!.allowedActions,'create');
137
137
  initThreeDotsDropdown();
138
138
  });
139
139
 
140
140
  async function saveRecord() {
141
- console.log('saveRecord isValid', isValid.value);
142
141
  if (!isValid.value) {
143
142
  validating.value = true;
144
143
  return;
@@ -154,12 +153,12 @@ async function saveRecord() {
154
153
  record: record.value,
155
154
  },
156
155
  });
157
- if (response?.error) {
156
+ if (response?.error && response?.error !== 'Operation aborted by hook') {
158
157
  showErrorTost(response.error);
159
158
  }
160
159
  saving.value = false;
161
160
  if (route.query.returnTo) {
162
- router.push(route.query.returnTo);
161
+ router.push(<string>route.query.returnTo);
163
162
  } else {
164
163
  router.push({
165
164
  name: 'resource-show',