firstly 0.3.0 → 0.4.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 (163) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/esm/SqlDatabase/FF_LogToConsole.js +9 -14
  3. package/esm/carbone/CarboneController.js +2 -1
  4. package/esm/changeLog/index.d.ts +0 -5
  5. package/esm/core/helper.d.ts +2 -0
  6. package/esm/core/helper.js +3 -0
  7. package/esm/core/index.d.ts +0 -0
  8. package/esm/core/index.js +5 -0
  9. package/esm/core/tailwind.d.ts +21 -0
  10. package/esm/core/tailwind.js +22 -0
  11. package/esm/core/tryCatch.d.ts +44 -0
  12. package/esm/core/tryCatch.js +34 -0
  13. package/esm/cron/server/index.js +1 -1
  14. package/esm/feedback/FeedbackController.js +3 -2
  15. package/esm/feedback/index.d.ts +7 -2
  16. package/esm/feedback/index.js +1 -2
  17. package/esm/feedback/server/index.d.ts +0 -5
  18. package/esm/feedback/server/index.js +1 -1
  19. package/esm/formats/strings.js +2 -2
  20. package/esm/index.d.ts +16 -0
  21. package/esm/index.js +13 -0
  22. package/esm/svelte/FF_Repo.svelte.d.ts +0 -2
  23. package/esm/svelte/FF_Repo.svelte.js +1 -17
  24. package/esm/svelte/helpers/debounce.js +1 -1
  25. package/esm/svelte/index.d.ts +2 -24
  26. package/esm/svelte/index.js +2 -22
  27. package/esm/{ui → svelte/ui}/Icon.svelte +1 -1
  28. package/esm/virtual/StateDemoEnum.d.ts +3 -3
  29. package/esm/virtual/StateDemoEnum.js +3 -3
  30. package/esm/virtual/UIEntity.js +1 -2
  31. package/package.json +6 -24
  32. package/esm/bin/cmd.d.ts +0 -1
  33. package/esm/bin/cmd.js +0 -638
  34. package/esm/feedback/ui/DialogIssue.svelte +0 -149
  35. package/esm/feedback/ui/DialogIssue.svelte.d.ts +0 -22
  36. package/esm/feedback/ui/DialogIssues.svelte +0 -114
  37. package/esm/feedback/ui/DialogIssues.svelte.d.ts +0 -22
  38. package/esm/feedback/ui/DialogMilestones.svelte +0 -43
  39. package/esm/feedback/ui/DialogMilestones.svelte.d.ts +0 -20
  40. package/esm/feedback/ui/Feedback.svelte +0 -16
  41. package/esm/feedback/ui/Feedback.svelte.d.ts +0 -18
  42. package/esm/internals/FF_Entity.d.ts +0 -2
  43. package/esm/internals/FF_Fields.d.ts +0 -11
  44. package/esm/internals/FF_Fields.js +0 -144
  45. package/esm/internals/cellsBuildor.d.ts +0 -47
  46. package/esm/internals/cellsBuildor.js +0 -141
  47. package/esm/internals/helper.d.ts +0 -49
  48. package/esm/internals/helper.js +0 -162
  49. package/esm/internals/index.d.ts +0 -78
  50. package/esm/internals/index.js +0 -45
  51. package/esm/internals/storeItem.d.ts +0 -19
  52. package/esm/internals/storeItem.js +0 -190
  53. package/esm/internals/storeList.d.ts +0 -34
  54. package/esm/internals/storeList.js +0 -108
  55. package/esm/internals/theme.d.ts +0 -4
  56. package/esm/internals/theme.js +0 -4
  57. package/esm/server/index.d.ts +0 -52
  58. package/esm/server/index.js +0 -87
  59. package/esm/svelte/FF_Cell.svelte +0 -103
  60. package/esm/svelte/FF_Cell.svelte.d.ts +0 -33
  61. package/esm/svelte/FF_Cell_Caption.svelte +0 -20
  62. package/esm/svelte/FF_Cell_Caption.svelte.d.ts +0 -31
  63. package/esm/svelte/FF_Cell_Display.svelte +0 -61
  64. package/esm/svelte/FF_Cell_Display.svelte.d.ts +0 -29
  65. package/esm/svelte/FF_Cell_Edit.svelte +0 -104
  66. package/esm/svelte/FF_Cell_Edit.svelte.d.ts +0 -32
  67. package/esm/svelte/FF_Cell_Error.svelte +0 -20
  68. package/esm/svelte/FF_Cell_Error.svelte.d.ts +0 -31
  69. package/esm/svelte/FF_Cell_Hint.svelte +0 -20
  70. package/esm/svelte/FF_Cell_Hint.svelte.d.ts +0 -31
  71. package/esm/svelte/FF_Config.svelte +0 -29
  72. package/esm/svelte/FF_Config.svelte.d.ts +0 -9
  73. package/esm/svelte/FF_Form.svelte +0 -155
  74. package/esm/svelte/FF_Form.svelte.d.ts +0 -37
  75. package/esm/svelte/FF_Grid.svelte +0 -257
  76. package/esm/svelte/FF_Grid.svelte.d.ts +0 -37
  77. package/esm/svelte/FF_Layout.svelte +0 -62
  78. package/esm/svelte/FF_Layout.svelte.d.ts +0 -31
  79. package/esm/svelte/actions/intersection.d.ts +0 -6
  80. package/esm/svelte/actions/intersection.js +0 -17
  81. package/esm/svelte/customField.d.ts +0 -69
  82. package/esm/svelte/customField.js +0 -4
  83. package/esm/svelte/dialog/DialogManagement.svelte +0 -98
  84. package/esm/svelte/dialog/DialogManagement.svelte.d.ts +0 -18
  85. package/esm/svelte/dialog/DialogPrimitive.svelte +0 -156
  86. package/esm/svelte/dialog/DialogPrimitive.svelte.d.ts +0 -38
  87. package/esm/svelte/dialog/dialog.d.ts +0 -58
  88. package/esm/svelte/dialog/dialog.js +0 -130
  89. package/esm/svelte/ff_Config.svelte.d.ts +0 -91
  90. package/esm/svelte/ff_Config.svelte.js +0 -111
  91. package/esm/svelte/firstly.css +0 -14
  92. package/esm/svelte/helpers.d.ts +0 -30
  93. package/esm/svelte/helpers.js +0 -38
  94. package/esm/svelte/tryCatch.d.ts +0 -12
  95. package/esm/svelte/tryCatch.js +0 -18
  96. package/esm/sveltekit/server/index.d.ts +0 -5
  97. package/esm/sveltekit/server/index.js +0 -24
  98. package/esm/ui/Button.svelte +0 -90
  99. package/esm/ui/Button.svelte.d.ts +0 -11
  100. package/esm/ui/Clipboardable.svelte +0 -25
  101. package/esm/ui/Clipboardable.svelte.d.ts +0 -12
  102. package/esm/ui/Field.svelte +0 -391
  103. package/esm/ui/Field.svelte.d.ts +0 -40
  104. package/esm/ui/FieldGroup.svelte +0 -117
  105. package/esm/ui/FieldGroup.svelte.d.ts +0 -44
  106. package/esm/ui/Grid.svelte +0 -262
  107. package/esm/ui/Grid.svelte.d.ts +0 -57
  108. package/esm/ui/Grid2.svelte +0 -290
  109. package/esm/ui/Grid2.svelte.d.ts +0 -57
  110. package/esm/ui/GridLoading.svelte +0 -58
  111. package/esm/ui/GridLoading.svelte.d.ts +0 -23
  112. package/esm/ui/GridPaginate.svelte +0 -69
  113. package/esm/ui/GridPaginate.svelte.d.ts +0 -23
  114. package/esm/ui/GridPaginate2.svelte +0 -25
  115. package/esm/ui/GridPaginate2.svelte.d.ts +0 -7
  116. package/esm/ui/Loading.svelte +0 -16
  117. package/esm/ui/Loading.svelte.d.ts +0 -31
  118. package/esm/ui/Tooltip.svelte +0 -45
  119. package/esm/ui/Tooltip.svelte.d.ts +0 -32
  120. package/esm/ui/dialog/DialogForm.svelte +0 -76
  121. package/esm/ui/dialog/DialogForm.svelte.d.ts +0 -21
  122. package/esm/ui/dialog/DialogManagement.svelte +0 -96
  123. package/esm/ui/dialog/DialogManagement.svelte.d.ts +0 -26
  124. package/esm/ui/dialog/DialogPrimitive.svelte +0 -90
  125. package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +0 -38
  126. package/esm/ui/dialog/FormEditAction.svelte +0 -62
  127. package/esm/ui/dialog/FormEditAction.svelte.d.ts +0 -31
  128. package/esm/ui/dialog/dialog.d.ts +0 -60
  129. package/esm/ui/dialog/dialog.js +0 -100
  130. package/esm/ui/index.d.ts +0 -6
  131. package/esm/ui/index.js +0 -20
  132. package/esm/ui/internals/FieldContainer.svelte +0 -39
  133. package/esm/ui/internals/FieldContainer.svelte.d.ts +0 -18
  134. package/esm/ui/internals/Input.svelte +0 -143
  135. package/esm/ui/internals/Input.svelte.d.ts +0 -37
  136. package/esm/ui/internals/Textarea.svelte +0 -66
  137. package/esm/ui/internals/Textarea.svelte.d.ts +0 -33
  138. package/esm/ui/internals/select/MultiSelectMelt.svelte +0 -260
  139. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +0 -32
  140. package/esm/ui/internals/select/Select2.svelte +0 -88
  141. package/esm/ui/internals/select/Select2.svelte.d.ts +0 -12
  142. package/esm/ui/internals/select/SelectMelt.svelte +0 -289
  143. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +0 -40
  144. package/esm/ui/internals/select/SelectRadio.svelte +0 -43
  145. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +0 -27
  146. package/esm/ui/link/Link.svelte +0 -33
  147. package/esm/ui/link/Link.svelte.d.ts +0 -33
  148. package/esm/ui/link/LinkPlus.svelte +0 -63
  149. package/esm/ui/link/LinkPlus.svelte.d.ts +0 -9
  150. package/esm/utils/tailwind.d.ts +0 -2
  151. package/esm/utils/tailwind.js +0 -3
  152. package/esm/utils/transition.d.ts +0 -9
  153. package/esm/utils/transition.js +0 -33
  154. /package/esm/{internals → core}/BaseEnum.d.ts +0 -0
  155. /package/esm/{internals → core}/BaseEnum.js +0 -0
  156. /package/esm/{internals → core}/FF_Entity.js +0 -0
  157. /package/esm/{internals → core}/common.d.ts +0 -0
  158. /package/esm/{internals → core}/common.js +0 -0
  159. /package/esm/{utils → core}/types.d.ts +0 -0
  160. /package/esm/{utils → core}/types.js +0 -0
  161. /package/esm/{ui → svelte/ui}/Icon.svelte.d.ts +0 -0
  162. /package/esm/{ui → svelte/ui}/LibIcon.d.ts +0 -0
  163. /package/esm/{ui → svelte/ui}/LibIcon.js +0 -0
@@ -1,141 +0,0 @@
1
- import {} from 'remult';
2
- import { getRelationFieldInfo } from 'remult/internals';
3
- import { BaseEnum } from './BaseEnum.js';
4
- import { getEnum } from './helper.js';
5
- /**
6
- * cellsBuildor is a function to build cells for a <Grid /> or <FieldGroup /> component.
7
- *
8
- * ```html
9
- * <script lang="ts">
10
- * import { repo } from 'remult'
11
- *
12
- * const cells = cellsBuildor(repo(Site), ['name', 'description'])
13
- * const store = storeList( repo(Site) )
14
- * $: store.fetch()
15
- * </script>
16
- *
17
- * <Grid {cells} {store} />
18
- * ```
19
- *
20
- */
21
- export function cellsBuildor(repo, inputBuildor) {
22
- const buildor = [];
23
- for (let i = 0; i < inputBuildor.length; i++) {
24
- const item = inputBuildor[i];
25
- let b;
26
- if (item instanceof Object) {
27
- b = { ...item, field: repo.fields[item.col] };
28
- }
29
- else {
30
- b = { col: item, field: repo.fields[item] };
31
- }
32
- // Let's tweak defaults...
33
- if (b.kind === undefined) {
34
- if (b.field?.options.href) {
35
- b.kind = 'field_link';
36
- }
37
- }
38
- buildor.push(b);
39
- }
40
- return buildor;
41
- }
42
- export function cellBuildor(repo, inputBuildor) {
43
- return cellsBuildor(repo, [inputBuildor])[0];
44
- }
45
- export const fieldsOf = (b) => {
46
- return b.filter((c) => c.field).map((c) => c.field) ?? [];
47
- };
48
- export const getPlaceholder = (fields) => {
49
- return fields.map((c) => c.caption).join(', ');
50
- };
51
- export const buildSearchWhere = (entity, fields, search) => {
52
- if (!search) {
53
- return [];
54
- }
55
- const f = [
56
- {
57
- $or: fields.map((f) => {
58
- const fnName = f.key + 'Filter';
59
- // @ts-ignore
60
- if (entity && entity[fnName]) {
61
- // @ts-ignore
62
- return entity[fnName](search);
63
- }
64
- // let's continue with the default behavior
65
- // return {}
66
- // }
67
- if (f.inputType === 'number') {
68
- return { [f.key]: search };
69
- }
70
- return containsWords([f], search);
71
- }),
72
- },
73
- ];
74
- return f;
75
- };
76
- export const containsWords = (fields, search) => {
77
- if (!search) {
78
- return {};
79
- }
80
- const sSplitted = search.split(' ').filter((s) => s.length > 0);
81
- if (fields.length === 1) {
82
- return {
83
- $and: sSplitted.map((s) => ({ [fields[0].key]: { $contains: s } })),
84
- };
85
- }
86
- return {
87
- $and: sSplitted.map((s) => {
88
- return { $or: fields.map((f) => ({ [f.key]: { $contains: s } })) };
89
- }),
90
- };
91
- };
92
- export const buildWhere = (entity, defaultWhere, fields_filter, fields_search, obj) => {
93
- const and = [];
94
- if (defaultWhere) {
95
- and.push(defaultWhere);
96
- }
97
- if (obj && obj.search) {
98
- and.push(...buildSearchWhere(entity, fields_search, obj.search));
99
- }
100
- for (const field of fields_filter) {
101
- const rfi = getRelationFieldInfo(field);
102
- // For relation fields, allow null as valid filter value (filters for NULL in DB)
103
- const hasValue = rfi?.type === 'toOne' ? obj && obj[field.key] !== undefined : obj && obj[field.key];
104
- if (hasValue) {
105
- if (field.inputType === 'checkbox') {
106
- // @ts-ignore
107
- and.push({ [field.key]: obj[field.key] });
108
- }
109
- else if (field.inputType === 'selectEnum') {
110
- const fnName = field.key + 'Filter';
111
- // @ts-ignore
112
- if (entity && entity[fnName]) {
113
- // @ts-ignore
114
- and.push(entity[fnName](obj[field.key]));
115
- }
116
- else {
117
- // @ts-ignore
118
- const theEnum = getEnum(field, obj[field.key]);
119
- // Take the where of the enum if it exists, or it's using this selection as a filter
120
- if (theEnum?.where) {
121
- and.push(theEnum.where);
122
- }
123
- else {
124
- const wheretoUse = theEnum?.where ?? new BaseEnum(obj[field.key]);
125
- // @ts-ignore
126
- and.push({ [field.key]: wheretoUse });
127
- }
128
- }
129
- }
130
- else if (rfi?.type === 'toOne') {
131
- // @ts-ignore (setting the id of the relation, null = filter for NULL)
132
- and.push({ [field.key]: obj[field.key] });
133
- }
134
- else {
135
- console.info(`Not handled filter field ${field.key} ${field.inputType}`);
136
- }
137
- }
138
- }
139
- // @ts-ignore
140
- return { $and: and };
141
- };
@@ -1,49 +0,0 @@
1
- import type { ClassType, ErrorInfo, FieldMetadata, LifecycleEvent, Repository } from 'remult';
2
- import type { BaseEnum, BaseItem } from './index.js';
3
- export declare function isError<T>(object: any): object is ErrorInfo<T>;
4
- export declare const getFirstInterestingField: <Entity>(repo: Repository<Entity>) => FieldMetadata<any, Entity>;
5
- export declare const getEntityDisplayValue: <Entity>(repo: Repository<Entity>, row: Entity) => BaseItem;
6
- export declare const getFieldLinkDisplayValue: (field: FieldMetadata, row: any) => BaseItem & {
7
- href: string;
8
- };
9
- export declare const getEntityDisplayValueFromField: (field: FieldMetadata, row: any) => BaseItem & {
10
- href: string;
11
- };
12
- export type MetaTypeRelation = {
13
- kind: 'relation';
14
- subKind: 'reference' | 'toOne' | 'toMany';
15
- repoTarget: Repository<any>;
16
- field: FieldMetadata;
17
- };
18
- type MetaTypeEnum = {
19
- kind: 'enum';
20
- subKind: 'single' | 'multi';
21
- values: BaseItem[];
22
- field: FieldMetadata;
23
- };
24
- type MetaTypePrimitive = {
25
- kind: 'primitive';
26
- subKind: string;
27
- field: FieldMetadata;
28
- };
29
- type MetaTypeSlot = {
30
- kind: 'slot';
31
- subKind: '???';
32
- };
33
- export type FieldMetaType = MetaTypeRelation | MetaTypeEnum | MetaTypePrimitive | MetaTypeSlot;
34
- export declare const getFieldMetaType: (field?: FieldMetadata, withHidden?: boolean) => FieldMetaType;
35
- export declare const displayWithDefaultAndSuffix: (field: FieldMetadata<any, any> | undefined, value: any) => string;
36
- export declare const getEnum: <T extends BaseEnum>(baseEnum: ClassType<T>, id: string | undefined | null) => T | undefined;
37
- export declare const getEnums: <T extends BaseEnum>(baseEnum: ClassType<T>) => T[];
38
- /**
39
- * To be used like:
40
- * ```ts
41
- * \@Entity('tasks', {
42
- * async deleting(item, e) {
43
- * await onDelete(item, e, 'prevent')
44
- * },
45
- * }
46
- * ```
47
- */
48
- export declare const onDelete: <T>(item: T, e: LifecycleEvent<T>, mode?: "prevent" | "cascade") => Promise<void>;
49
- export {};
@@ -1,162 +0,0 @@
1
- import { EntityError, getEntityRef, getValueList } from 'remult';
2
- import { getRelationFieldInfo } from 'remult/internals';
3
- import { suffixWithS } from '../formats/strings.js';
4
- export function isError(object) {
5
- return object;
6
- }
7
- export const getFirstInterestingField = (repo) => {
8
- const fields = repo.metadata.fields.toArray();
9
- for (let i = 0; i < fields.length; i++) {
10
- // Let's find the most relevant field to display...
11
- if (fields[i].key !== 'id' &&
12
- fields[i].key !== 'createdAt' &&
13
- fields[i].options.skipForDefaultField !== true) {
14
- return fields[i];
15
- }
16
- }
17
- return fields[0];
18
- };
19
- export const getEntityDisplayValue = (repo, row) => {
20
- if (repo.metadata.options.displayValue) {
21
- return repo.metadata.options.displayValue(row);
22
- }
23
- const field = getFirstInterestingField(repo);
24
- // REMULT P3 JYC: If it's an enum, it's not working...
25
- // @ts-ignore (added for row?.id)
26
- return { caption: row ? field.displayValue(row) : '-', id: row?.id ? row.id : '' };
27
- };
28
- export const getFieldLinkDisplayValue = (field, row) => {
29
- const caption = field.displayValue(row);
30
- let href = '';
31
- if (field.options.href) {
32
- href = field.options.href(row);
33
- }
34
- return { id: '', caption, href };
35
- };
36
- export const getEntityDisplayValueFromField = (field, row) => {
37
- if (row === null || row === undefined) {
38
- return { href: '/', id: '', caption: '-' };
39
- }
40
- const repo = getEntityRef(row).repository;
41
- return { href: '', ...getEntityDisplayValue(repo, row) };
42
- };
43
- // or it's a slot or it will return the field
44
- export const getFieldMetaType = (field, withHidden = false) => {
45
- if (field === undefined) {
46
- return { kind: 'slot', subKind: '???' };
47
- }
48
- // is it a relation?
49
- const fieldRelationInfo = getRelationFieldInfo(field);
50
- if (fieldRelationInfo) {
51
- return {
52
- kind: 'relation',
53
- subKind: fieldRelationInfo.type,
54
- repoTarget: fieldRelationInfo.toRepo,
55
- field,
56
- };
57
- }
58
- if (field.options?.inputType === 'selectArrayEnum') {
59
- return {
60
- kind: 'enum',
61
- subKind: 'multi',
62
- // @ts-ignore
63
- values: field.options.valueConverter.values,
64
- field,
65
- };
66
- }
67
- // REMULT P2 JYC: Any idea to know if it's an enum? and extract values?
68
- // const ttt = getValueList(field)
69
- // console.log(`ttt`, ttt)
70
- // Error: ValueType not yet initialized, did you forget to call @ValueListFieldType on function String()
71
- // is it an enum?
72
- // @ts-ignore
73
- if (field.options?.valueConverter?.values) {
74
- // console.log(`field.options.valueConverter.values`, field.options.valueConverter.values)
75
- // @ts-ignore
76
- const values = field.options.valueConverter.values;
77
- return {
78
- kind: 'enum',
79
- subKind: 'single',
80
- values: withHidden ? values : values.filter((v) => !v.hide),
81
- field,
82
- };
83
- }
84
- // it's a primitive
85
- return { kind: 'primitive', subKind: field.inputType ?? 'text', field };
86
- };
87
- export const displayWithDefaultAndSuffix = (field, value) => {
88
- const toRet = [];
89
- if (field && field.valueConverter?.displayValue && !field.isServerExpression) {
90
- toRet.push(field.valueConverter?.displayValue(value) ?? '-');
91
- }
92
- else {
93
- // toRet.push(value ?? '-')
94
- toRet.push(field?.displayValue ? field?.displayValue({ [field.key]: value }) : (value ?? '-'));
95
- }
96
- if (value === undefined || value === null) {
97
- return '';
98
- }
99
- if (field?.options.suffix) {
100
- if (field.options.suffixWithS) {
101
- toRet.push(suffixWithS(value, field.options.suffix));
102
- }
103
- else {
104
- toRet.push(field.options.suffix);
105
- }
106
- }
107
- return toRet.join(' ');
108
- };
109
- // FIXME: to remove ?
110
- export const getEnum = (baseEnum, id) => {
111
- if (!id) {
112
- return undefined;
113
- }
114
- // @ts-ignore
115
- const found = getValueList(baseEnum).find((c) => c.id === id);
116
- return found;
117
- };
118
- // FIXME: to remove ?
119
- export const getEnums = (baseEnum) => {
120
- return getValueList(baseEnum) || [];
121
- };
122
- /**
123
- * To be used like:
124
- * ```ts
125
- * \@Entity('tasks', {
126
- * async deleting(item, e) {
127
- * await onDelete(item, e, 'prevent')
128
- * },
129
- * }
130
- * ```
131
- */
132
- export const onDelete = async (item, e, mode = 'prevent') => {
133
- const toManies = e.repository.fields
134
- .toArray()
135
- .map((f) => {
136
- return {
137
- f: f,
138
- fi: getRelationFieldInfo(f),
139
- };
140
- })
141
- .filter((f) => f.fi?.type === 'toMany');
142
- const checks = await Promise.all(toManies.map(async (f_fi) => {
143
- // @ts-ignore
144
- const count = await e.repository.relations(item)[f_fi.f.key].count();
145
- return { ...f_fi, count };
146
- }));
147
- const nonEmptyRelations = checks.filter((check) => check.count > 0);
148
- if (nonEmptyRelations.length > 0) {
149
- if (mode === 'prevent') {
150
- const relationNames = nonEmptyRelations.map((r) => r.f.caption).join(', ');
151
- throw new EntityError({ message: `Can't with existing: ${relationNames}` });
152
- }
153
- else if (mode === 'cascade') {
154
- nonEmptyRelations.forEach(async (r) => {
155
- const where = Object.entries(r.fi?.getFields().fields ?? {}).map(([key, value]) => {
156
- return { [key]: item[value] };
157
- });
158
- await r.fi?.toRepo.deleteMany({ where });
159
- });
160
- }
161
- }
162
- };
@@ -1,78 +0,0 @@
1
- import type { FindOptionsBase } from 'remult';
2
- import type { ColumnDeciderArgs } from '../changeLog/index.js';
3
- import { default as Button } from '../ui/Button.svelte';
4
- import { default as Clipboardable } from '../ui/Clipboardable.svelte';
5
- import type { dialog } from '../ui/dialog/dialog.js';
6
- import { default as DialogManagement } from '../ui/dialog/DialogManagement.svelte';
7
- import { default as FormEditAction } from '../ui/dialog/FormEditAction.svelte';
8
- import { default as Field } from '../ui/Field.svelte';
9
- import { default as FieldGroup } from '../ui/FieldGroup.svelte';
10
- import { default as Grid } from '../ui/Grid.svelte';
11
- import { default as Grid2 } from '../ui/Grid2.svelte';
12
- import { default as GridPaginate } from '../ui/GridPaginate.svelte';
13
- import { default as GridPaginate2 } from '../ui/GridPaginate2.svelte';
14
- import { default as Icon } from '../ui/Icon.svelte';
15
- import { default as FieldContainer } from '../ui/internals/FieldContainer.svelte';
16
- import { default as SelectMelt } from '../ui/internals/select/SelectMelt.svelte';
17
- import { default as Link } from '../ui/link/Link.svelte';
18
- import { default as LinkPlus } from '../ui/link/LinkPlus.svelte';
19
- import { default as Loading } from '../ui/Loading.svelte';
20
- import { default as Tooltip } from '../ui/Tooltip.svelte';
21
- import type { BaseItem, BaseItemLight, FF_Icon } from './BaseEnum.js';
22
- import type { CellsInput } from './cellsBuildor.js';
23
- import { FF_Role } from './common.js';
24
- import { storeItem, type StoreItem } from './storeItem.js';
25
- import { storeList } from './storeList.js';
26
- export { Field, FormEditAction, Grid, Grid2, GridPaginate, GridPaginate2, FieldGroup, Icon, Link, LinkPlus, Loading, Button, Tooltip, DialogManagement, FieldContainer, SelectMelt, Clipboardable, };
27
- export type { BaseEnumOptions } from './BaseEnum.js';
28
- export type { BaseItem, BaseItemLight };
29
- export type { DialogMetaDataInternal } from '../ui/dialog/dialog.js';
30
- export type { CellsInput };
31
- export type { Cell, VisibilityMode } from './cellsBuildor.js';
32
- export type { FF_FindOptions } from './storeList.js';
33
- export type { StoreItem };
34
- export type StoreList<T> = ReturnType<typeof storeList<T>>;
35
- export type { ResolvedType, UnArray, RecursivePartial } from '../utils/types.js';
36
- export { FF_Fields } from './FF_Fields.js';
37
- export { FF_Entity } from './FF_Entity.js';
38
- export { FF_LogToConsole } from '../SqlDatabase/FF_LogToConsole.js';
39
- export { BaseEnum } from './BaseEnum.js';
40
- export { dialog } from '../ui/dialog/dialog.js';
41
- export { getEntityDisplayValue, displayWithDefaultAndSuffix, isError, getFieldLinkDisplayValue, getEnum, getEnums, onDelete, } from './helper.js';
42
- export { buildWhere, getPlaceholder, buildSearchWhere, cellsBuildor, cellBuildor, fieldsOf, containsWords, } from './cellsBuildor.js';
43
- export { storeItem };
44
- export { storeList };
45
- export { tw } from '../utils/tailwind.js';
46
- export { FF_Role };
47
- export { FilterEntity } from '../virtual/FilterEntity.js';
48
- export { UIEntity } from '../virtual/UIEntity.js';
49
- export { LibIcon_Empty, LibIcon_Forbidden, LibIcon_ChevronDown, LibIcon_ChevronUp, LibIcon_ChevronLeft, LibIcon_ChevronRight, LibIcon_Search, LibIcon_Check, LibIcon_MultiCheck, LibIcon_Add, LibIcon_MultiAdd, LibIcon_Edit, LibIcon_Delete, LibIcon_Cross, LibIcon_Save, LibIcon_Man, LibIcon_Woman, LibIcon_Send, LibIcon_Load, LibIcon_Settings, LibIcon_Sort, LibIcon_SortAsc, LibIcon_SortDesc, } from '../ui/LibIcon.js';
50
- export type { FF_Icon };
51
- declare module 'remult' {
52
- interface FieldOptions<entityType, valueType> {
53
- placeholder?: string;
54
- suffix?: string;
55
- suffixWithS?: boolean;
56
- suffixEdit?: string;
57
- suffixEditWithS?: boolean;
58
- styleRadioUntil?: number;
59
- step?: '1' | '0.1' | '0.01' | '0.5';
60
- href?: (item: entityType) => string;
61
- findOptionsForEdit?: ((entity: entityType) => FindOptionsBase<valueType>) | FindOptionsBase<valueType>;
62
- findOptionsLimit?: number;
63
- createOptionWhenNoResult?: {
64
- onCreateRequest: (item: entityType, strCreateNew: string) => Parameters<typeof dialog.form>;
65
- onSuccess: (entity: entityType, newItem: any) => Promise<void>;
66
- onError?: () => void;
67
- };
68
- default_select_if_one_item?: boolean;
69
- multiSelect?: boolean;
70
- filterNobodyLabel?: string;
71
- skipForDefaultField?: boolean;
72
- }
73
- interface EntityOptions<entityType> {
74
- searchableFind?: (str: string) => FindOptionsBase<entityType>;
75
- displayValue?: (item: entityType) => BaseItem;
76
- changeLog?: false | ColumnDeciderArgs<entityType>;
77
- }
78
- }
@@ -1,45 +0,0 @@
1
- import { default as Button } from '../ui/Button.svelte';
2
- import { default as Clipboardable } from '../ui/Clipboardable.svelte';
3
- import { default as DialogManagement } from '../ui/dialog/DialogManagement.svelte';
4
- import { default as FormEditAction } from '../ui/dialog/FormEditAction.svelte';
5
- import { default as Field } from '../ui/Field.svelte';
6
- import { default as FieldGroup } from '../ui/FieldGroup.svelte';
7
- import { default as Grid } from '../ui/Grid.svelte';
8
- import { default as Grid2 } from '../ui/Grid2.svelte';
9
- import { default as GridPaginate } from '../ui/GridPaginate.svelte';
10
- import { default as GridPaginate2 } from '../ui/GridPaginate2.svelte';
11
- import { default as Icon } from '../ui/Icon.svelte';
12
- import { default as FieldContainer } from '../ui/internals/FieldContainer.svelte';
13
- import { default as SelectMelt } from '../ui/internals/select/SelectMelt.svelte';
14
- import { default as Link } from '../ui/link/Link.svelte';
15
- import { default as LinkPlus } from '../ui/link/LinkPlus.svelte';
16
- import { default as Loading } from '../ui/Loading.svelte';
17
- import { default as Tooltip } from '../ui/Tooltip.svelte';
18
- import { FF_Role } from './common.js';
19
- import { storeItem } from './storeItem.js';
20
- import { storeList } from './storeList.js';
21
- // ******************************
22
- // Svelte Components
23
- // ******************************
24
- export { Field, FormEditAction, Grid, Grid2, GridPaginate, GridPaginate2, FieldGroup, Icon, Link, LinkPlus, Loading, Button, Tooltip, DialogManagement, FieldContainer, SelectMelt, Clipboardable, };
25
- // ******************************
26
- // Helpers
27
- // ******************************
28
- export { FF_Fields } from './FF_Fields.js';
29
- export { FF_Entity } from './FF_Entity.js';
30
- export { FF_LogToConsole } from '../SqlDatabase/FF_LogToConsole.js';
31
- export { BaseEnum } from './BaseEnum.js';
32
- export { dialog } from '../ui/dialog/dialog.js';
33
- export { getEntityDisplayValue, displayWithDefaultAndSuffix, isError, getFieldLinkDisplayValue, getEnum, getEnums, onDelete, } from './helper.js';
34
- export { buildWhere, getPlaceholder, buildSearchWhere, cellsBuildor, cellBuildor, fieldsOf, containsWords, } from './cellsBuildor.js';
35
- export { storeItem };
36
- export { storeList };
37
- export { tw } from '../utils/tailwind.js';
38
- export { FF_Role };
39
- // Hummm... I don't know if we should keep it...
40
- export { FilterEntity } from '../virtual/FilterEntity.js';
41
- export { UIEntity } from '../virtual/UIEntity.js';
42
- // ******************************
43
- // Icons
44
- // ******************************
45
- export { LibIcon_Empty, LibIcon_Forbidden, LibIcon_ChevronDown, LibIcon_ChevronUp, LibIcon_ChevronLeft, LibIcon_ChevronRight, LibIcon_Search, LibIcon_Check, LibIcon_MultiCheck, LibIcon_Add, LibIcon_MultiAdd, LibIcon_Edit, LibIcon_Delete, LibIcon_Cross, LibIcon_Save, LibIcon_Man, LibIcon_Woman, LibIcon_Send, LibIcon_Load, LibIcon_Settings, LibIcon_Sort, LibIcon_SortAsc, LibIcon_SortDesc, } from '../ui/LibIcon.js';
@@ -1,19 +0,0 @@
1
- import type { EntityFilter, ErrorInfo, FindOptions, Repository } from 'remult';
2
- export interface StoreItem<T> {
3
- subscribe: (run: (value: TheStoreItem<T>) => void) => () => void;
4
- create: (item: Partial<T>) => void;
5
- set: (newItem: TheStoreItem<T>) => void;
6
- fetch: (idOrWhere: string | number | EntityFilter<T>, options?: FindOptions<T>, onNewData?: (item: T | undefined) => void) => Promise<void>;
7
- save: () => Promise<T | undefined>;
8
- delete: () => Promise<void>;
9
- onChange: (prop: keyof T, callback: (newValue: any, oldValue: any) => void) => void;
10
- }
11
- type TheStoreItem<T> = {
12
- item: T | undefined;
13
- loading?: boolean;
14
- initLoading?: boolean;
15
- errors: ErrorInfo<T> | undefined;
16
- globalError?: string | undefined;
17
- };
18
- export declare const storeItem: <T>(repo: Repository<T>, initValues?: TheStoreItem<T>) => StoreItem<T>;
19
- export {};
@@ -1,190 +0,0 @@
1
- import { BROWSER } from 'esm-env';
2
- import { derived, get, writable } from 'svelte/store';
3
- import { ff_Log } from '../index.js';
4
- import { isError } from './helper.js';
5
- export const storeItem = (repo, initValues = {
6
- item: undefined,
7
- loading: true,
8
- initLoading: true,
9
- errors: undefined,
10
- globalError: undefined,
11
- }) => {
12
- const internalStore = writable(initValues);
13
- // Function to watch changes on a specific property of `item`
14
- const onChange = (prop, callback) => {
15
- const itemProperty = derived(internalStore, ($s) => $s.item && $s.item[prop]);
16
- let oldValue;
17
- // Subscribe to the derived store to monitor changes
18
- itemProperty.subscribe((newValue) => {
19
- if (newValue !== oldValue) {
20
- if (oldValue !== undefined) {
21
- // to avoid running on initial undefined state
22
- callback(newValue, oldValue);
23
- }
24
- oldValue = newValue;
25
- }
26
- });
27
- };
28
- return {
29
- subscribe: internalStore.subscribe,
30
- create: (item) => {
31
- internalStore.set({
32
- item: repo.create(item),
33
- loading: false,
34
- initLoading: false,
35
- errors: {},
36
- globalError: undefined,
37
- });
38
- },
39
- // set: internalStore.set,
40
- set: (newItem) => {
41
- internalStore.update(() => {
42
- return { ...newItem };
43
- });
44
- },
45
- /**
46
- * Fetch by ID or WHERE clause
47
- * ```ts
48
- * // By ID (string or number)
49
- * store.fetch(123)
50
- * store.fetch('abc')
51
- *
52
- * // By WHERE clause (object)
53
- * store.fetch({ siteId: 123 })
54
- *
55
- * // With composite keys, build the id with
56
- * const id = repo.metadata.idMetadata.getId({a:1,b:2})
57
- * store.fetch(id)
58
- * ```
59
- */
60
- fetch: async (idOrWhere, options, onNewData) => {
61
- if (BROWSER) {
62
- internalStore.update((s) => ({ ...s, loading: true }));
63
- try {
64
- const isId = typeof idOrWhere === 'string' || typeof idOrWhere === 'number';
65
- const item = isId
66
- ? await repo.findId(idOrWhere, options)
67
- : await repo.findFirst(idOrWhere, options);
68
- internalStore.update((s) => ({
69
- ...s,
70
- loading: false,
71
- initLoading: false,
72
- item: item ?? {},
73
- errors: undefined,
74
- globalError: undefined,
75
- }));
76
- if (onNewData) {
77
- onNewData(item ?? undefined);
78
- }
79
- }
80
- catch (error) {
81
- if (isError(error)) {
82
- internalStore.update((s) => ({
83
- ...s,
84
- loading: false,
85
- initLoading: false,
86
- item: {},
87
- errors: {},
88
- // @ts-ignore
89
- globalError: error.message,
90
- }));
91
- }
92
- }
93
- }
94
- },
95
- /**
96
- * `.save()` will `update` or `insert` the current item.
97
- */
98
- save: async () => {
99
- const s = get(internalStore);
100
- try {
101
- if (!s.item) {
102
- return;
103
- }
104
- internalStore.update((s) => ({ ...s, loading: true }));
105
- const item = await repo.save(s.item);
106
- internalStore.update((s) => ({
107
- ...s,
108
- loading: false,
109
- item,
110
- errors: undefined,
111
- globalError: undefined,
112
- }));
113
- return item;
114
- }
115
- catch (error) {
116
- if (isError(error)) {
117
- if (!error.modelState) {
118
- internalStore.update((s) => ({
119
- ...s,
120
- loading: false,
121
- item: s.item,
122
- errors: undefined,
123
- globalError: error.message,
124
- }));
125
- }
126
- else {
127
- const errors = {};
128
- for (const key in error.modelState) {
129
- // @ts-ignore
130
- errors[key] = error.modelState[key];
131
- }
132
- internalStore.update((s) => ({
133
- ...s,
134
- loading: false,
135
- item: s.item,
136
- errors,
137
- globalError: undefined,
138
- }));
139
- }
140
- }
141
- // After we updated everything, let's throw the error
142
- throw error;
143
- }
144
- },
145
- delete: async () => {
146
- const s = get(internalStore);
147
- if (!s.item) {
148
- ff_Log.error(`To delete an item, you need set it first.`);
149
- return;
150
- }
151
- try {
152
- internalStore.update((s) => ({ ...s, loading: true }));
153
- await repo.delete(s.item);
154
- internalStore.update((s) => ({
155
- ...s,
156
- loading: false,
157
- }));
158
- }
159
- catch (error) {
160
- if (isError(error)) {
161
- if (!error.modelState) {
162
- internalStore.update((s) => ({
163
- ...s,
164
- loading: false,
165
- item: s.item,
166
- errors: undefined,
167
- globalError: error.message,
168
- }));
169
- }
170
- else {
171
- const errors = {};
172
- for (const key in error.modelState) {
173
- // @ts-ignore
174
- errors[key] = error.modelState[key];
175
- }
176
- internalStore.update((s) => ({
177
- ...s,
178
- loading: false,
179
- item: s.item,
180
- errors,
181
- globalError: undefined,
182
- }));
183
- }
184
- }
185
- throw error;
186
- }
187
- },
188
- onChange,
189
- };
190
- };