@fibery/views 18.0.4 → 19.0.1

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 (63) hide show
  1. package/lib/src/field-utils/reference-collection.d.ts +5 -10
  2. package/lib/src/field-utils/reference-collection.js +41 -19
  3. package/lib/src/field-utils/rich-text.d.ts +5 -4
  4. package/lib/src/field-utils/rich-text.js +22 -11
  5. package/lib/src/index.d.ts +28 -16
  6. package/lib/src/index.js +1 -1
  7. package/lib/src/private/board.d.ts +15 -11
  8. package/lib/src/private/board.js +8 -7
  9. package/lib/src/private/calendar.d.ts +14 -10
  10. package/lib/src/private/calendar.js +4 -3
  11. package/lib/src/private/feed.d.ts +14 -10
  12. package/lib/src/private/feed.js +4 -3
  13. package/lib/src/private/form.d.ts +25 -3
  14. package/lib/src/private/form.js +3 -3
  15. package/lib/src/private/map.d.ts +14 -10
  16. package/lib/src/private/map.js +4 -3
  17. package/lib/src/private/smart-folder.d.ts +23 -15
  18. package/lib/src/private/smart-folder.js +16 -13
  19. package/lib/src/private/timeline.d.ts +39 -10
  20. package/lib/src/private/timeline.js +8 -6
  21. package/lib/src/private/units.d.ts +10 -6
  22. package/lib/src/private/units.js +43 -22
  23. package/lib/src/private/utils.d.ts +64 -17
  24. package/lib/src/private/utils.js +26 -20
  25. package/lib/src/truthy.d.ts +1 -0
  26. package/lib/src/truthy.js +7 -0
  27. package/lib/src/unit-definitions/avatar-collection.js +24 -19
  28. package/lib/src/unit-definitions/avatar.js +23 -15
  29. package/lib/src/unit-definitions/collection-count.js +7 -7
  30. package/lib/src/unit-definitions/file-collection-count.js +9 -7
  31. package/lib/src/unit-definitions/file-compact-collection.js +9 -7
  32. package/lib/src/unit-definitions/file-compact-reference.js +5 -4
  33. package/lib/src/unit-definitions/file-reference.js +6 -4
  34. package/lib/src/unit-definitions/files-gallery.js +9 -7
  35. package/lib/src/unit-definitions/files-l-list-item.js +6 -4
  36. package/lib/src/unit-definitions/files-l-list.js +9 -7
  37. package/lib/src/unit-definitions/files-list-item.js +6 -4
  38. package/lib/src/unit-definitions/files-list.js +9 -7
  39. package/lib/src/unit-definitions/number.js +2 -4
  40. package/lib/src/unit-definitions/progress-bar.js +1 -4
  41. package/lib/src/unit-definitions/reference-collection.js +4 -3
  42. package/lib/src/unit-definitions/reference.js +17 -5
  43. package/lib/src/unit-definitions/rich-text-snippet.d.ts +1 -0
  44. package/lib/src/unit-definitions/rich-text-snippet.js +6 -11
  45. package/lib/src/unit-utils/decimal.js +10 -6
  46. package/lib/src/unit-utils/get-export-value.d.ts +1 -1
  47. package/lib/src/unit-utils/get-export-value.js +2 -1
  48. package/lib/src/unit-utils/get-field-label.js +2 -2
  49. package/lib/src/unit-utils/wrap-normalized-in-expression.d.ts +3 -0
  50. package/lib/src/unit-utils/wrap-normalized-in-expression.js +14 -0
  51. package/lib/src/units/board.d.ts +6 -3
  52. package/lib/src/units/canvas/index.d.ts +6 -3
  53. package/lib/src/units/default.d.ts +6 -3
  54. package/lib/src/units/gantt.d.ts +6 -3
  55. package/lib/src/units/grid.d.ts +6 -3
  56. package/lib/src/units/grid.js +4 -0
  57. package/lib/src/units/list.d.ts +6 -3
  58. package/lib/src/units/make-factory.d.ts +10 -9
  59. package/lib/src/units/make-factory.js +26 -10
  60. package/lib/src/units/types.d.ts +1 -1
  61. package/package.json +26 -26
  62. package/lib/jest.config.d.ts +0 -2
  63. package/lib/jest.config.js +0 -32
@@ -7,6 +7,7 @@ exports.enableHideWhenEmptyForCheckedUnits = exports.collectGarbage = exports.fi
7
7
  const visitors_1 = require("@fibery/expression-utils/src/visitors");
8
8
  const immutability_helper_1 = __importDefault(require("immutability-helper"));
9
9
  const get_1 = __importDefault(require("lodash/get"));
10
+ const truthy_1 = require("../truthy");
10
11
  const isEqual_1 = __importDefault(require("lodash/isEqual"));
11
12
  const units_1 = require("./units");
12
13
  const utils_1 = require("./utils");
@@ -16,7 +17,7 @@ const visitSmartFolder = (smartFolder, visitor) => (0, immutability_helper_1.def
16
17
  $apply: (items = []) => {
17
18
  const isOldSmartFolder = !items.every((item) => Object.hasOwn(item, "groupBy"));
18
19
  const removedItemsIndexes = items
19
- .map((item, index) => (visitor.visitQueryExpression(item.query) ? null : index))
20
+ .map((item, index) => visitor.visitQueryExpression(item.query) ? null : index)
20
21
  .filter((value) => value !== null);
21
22
  return items
22
23
  .map((item) => {
@@ -76,9 +77,9 @@ const visitSmartFolder = (smartFolder, visitor) => (0, immutability_helper_1.def
76
77
  $apply: (units) => {
77
78
  return units
78
79
  ? units
79
- .filter((unit) => Boolean(unit))
80
+ .filter(truthy_1.truthy)
80
81
  .map((unit) => (0, utils_1.visitViewUnit)(fromType, unit, visitor))
81
- .filter((unit) => (0, utils_1.isUnitExpressionValid)(unit))
82
+ .filter(utils_1.isUnitExpressionValid)
82
83
  .map((unit, index, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit)
83
84
  .filter((unit) => unit !== utils_1.REMOVE)
84
85
  : undefined;
@@ -153,7 +154,7 @@ const deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression = (schema, gr
153
154
  }
154
155
  return null;
155
156
  })
156
- .filter(Boolean);
157
+ .filter(truthy_1.truthy);
157
158
  return entries.length > 0 ? Object.fromEntries(entries) : null;
158
159
  };
159
160
  exports.deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression = deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression;
@@ -228,23 +229,25 @@ const fixContextExpressionWithBrokenPath = (schema, view, defaultContextExpressi
228
229
  visitContextExpression: (fromType, expression) => (0, utils_1.resetContextExpressionIfBroken)(schema, fromType, expression, defaultContextExpression),
229
230
  });
230
231
  exports.fixContextExpressionWithBrokenPath = fixContextExpressionWithBrokenPath;
231
- const fixUserSelectedUnitsInSmartFolder = (schema, view, { unitDefinitions, getDefaultUnitTypeForField }) => {
232
+ const fixUserSelectedUnitsInSmartFolder = (schema, view, { unitDefinitions, getDefaultUnitTypeForField, }) => {
232
233
  return visitSmartFolder(view, {
233
234
  visitQueryExpression: (query) => query,
234
235
  visitGroupByExpression: (groupBy) => groupBy,
235
236
  visitFilter: (_fromType, filter) => filter,
236
237
  visitExpression: (_fromType, expression) => expression,
237
238
  visitViewUnit: (fromType, unit, units) => {
238
- const { type, expression } = unit;
239
- if (type === "rich-text" && view?.["fibery/type"] === "grid") {
240
- if (unit.checked) {
241
- const snippetsUnits = units?.filter((x) => x.type === "rich-text-snippet");
242
- const snippetUnitForField = snippetsUnits?.find((x) => (0, isEqual_1.default)(x.expression, expression));
243
- if (snippetUnitForField && !snippetUnitForField.checked) {
244
- snippetUnitForField.checked = true;
239
+ if (unit.kind !== "user-button") {
240
+ // Migration: "rich-text" is a legacy unit type not in the current type system
241
+ if (unit.type === "rich-text" && view?.["fibery/type"] === "grid") {
242
+ if (unit.checked) {
243
+ const snippetsUnits = units.filter((x) => x.kind === "field" && x.type === "rich-text-snippet");
244
+ const snippetUnitForField = snippetsUnits.find((x) => (0, isEqual_1.default)(x.expression, unit.expression));
245
+ if (snippetUnitForField && !snippetUnitForField.checked) {
246
+ snippetUnitForField.checked = true;
247
+ }
245
248
  }
249
+ return utils_1.REMOVE;
246
250
  }
247
- return utils_1.REMOVE;
248
251
  }
249
252
  return (0, units_1.fixViewUnit)(schema, fromType, unit, units, { unitDefinitions, getDefaultUnitTypeForField });
250
253
  },
@@ -1,10 +1,39 @@
1
- export function replaceNamesWithIdsInTimelineView(schema: any, view: any): any;
2
- export function replaceIdsWithNamesInTimelineView(schema: any, view: any): any;
3
- export function deleteExpressionWithNotFoundFieldsOrTypesInTimelineView(schema: any, view: any, ensureAxisInvariant: any, canGroupMetaItem?: (metaItem: any) => boolean): any;
4
- export function fixUserSelectedUnitsInTimelineView(schema: any, view: any, { unitDefinitions, getDefaultUnitTypeForField }: {
5
- unitDefinitions: any;
6
- getDefaultUnitTypeForField: any;
7
- }): any;
8
- export function fixContextExpressionWithBrokenPath(schema: any, view: any, defaultContextExpression: any): any;
9
- export function collectGarbage(view: any): any;
10
- export function enableHideWhenEmptyForCheckedEditableUnits(view: any): any;
1
+ import type { Expression, Query } from "@fibery/expression-utils/src/types";
2
+ import type { FieldObject, Schema } from "@fibery/schema";
3
+ import type { UnitDefinitions, ViewFilter, ViewRecord } from "./utils";
4
+ import { Unit } from "@fibery/views/src/units/types";
5
+ type GroupByEntry = {
6
+ expression: Expression;
7
+ [k: string]: unknown;
8
+ };
9
+ type GroupByExpression = Record<string, GroupByEntry>;
10
+ type TimelineMetaItem = {
11
+ query?: Query | null;
12
+ filter?: ViewFilter | null;
13
+ yExpression?: Expression | null;
14
+ startExpression?: Expression | null;
15
+ endExpression?: Expression | null;
16
+ secondaryStartExpression?: Expression | null;
17
+ secondaryEndExpression?: Expression | null;
18
+ contextExpression?: Expression | null;
19
+ units?: Unit[] | null;
20
+ colorCoding?: {
21
+ expression: Expression;
22
+ [k: string]: unknown;
23
+ }[] | null;
24
+ dependencyExpression?: Expression | null;
25
+ groupBy?: GroupByExpression | null;
26
+ groupingExpression?: GroupByExpression | null;
27
+ [k: string]: unknown;
28
+ };
29
+ export declare const replaceNamesWithIdsInTimelineView: (schema: Schema, view: ViewRecord) => any;
30
+ export declare const replaceIdsWithNamesInTimelineView: (schema: Schema, view: ViewRecord) => any;
31
+ export declare const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView: (schema: Schema, view: ViewRecord, ensureAxisInvariant: boolean, canGroupMetaItem?: (_metaItem: TimelineMetaItem) => boolean) => any;
32
+ export declare const fixUserSelectedUnitsInTimelineView: (schema: Schema, view: ViewRecord, { unitDefinitions, getDefaultUnitTypeForField, }: {
33
+ unitDefinitions: UnitDefinitions;
34
+ getDefaultUnitTypeForField: (fieldObject: FieldObject, allowedUnits: Unit[]) => string | undefined;
35
+ }) => any;
36
+ export declare const fixContextExpressionWithBrokenPath: (schema: Schema, view: ViewRecord, defaultContextExpression: Expression) => any;
37
+ export declare const collectGarbage: (view: ViewRecord) => any;
38
+ export declare const enableHideWhenEmptyForCheckedEditableUnits: (view: ViewRecord) => any;
39
+ export {};
@@ -13,6 +13,7 @@ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
13
13
  const set_1 = __importDefault(require("lodash/set"));
14
14
  const some_1 = __importDefault(require("lodash/some"));
15
15
  const smart_folder_1 = require("./smart-folder");
16
+ const truthy_1 = require("../truthy");
16
17
  const units_1 = require("./units");
17
18
  const utils_1 = require("./utils");
18
19
  const visitAxisSingle = (axis, visitor) => {
@@ -26,10 +27,11 @@ const visitAxisSingle = (axis, visitor) => {
26
27
  units: axis.units &&
27
28
  axis.units
28
29
  .map((unit) => (0, utils_1.visitViewUnit)(fromType, unit, visitor))
29
- .filter((unit) => (0, utils_1.isUnitExpressionValid)(unit))
30
+ .filter(utils_1.isUnitExpressionValid)
30
31
  .map((unit, idx, units) => (visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit))
31
32
  .filter((unit) => unit !== utils_1.REMOVE),
32
- groupByExpression: axis.groupByExpression && firstOrNull(visitor.visitExpression(fromType, [axis.groupByExpression])),
33
+ groupByExpression: axis.groupByExpression &&
34
+ firstOrNull(visitor.visitExpression(fromType, [axis.groupByExpression])),
33
35
  };
34
36
  if (!axisResult.query) {
35
37
  return null;
@@ -101,9 +103,9 @@ const visitView = (view, visitor) => (0, immutability_helper_1.default)(view, {
101
103
  units: {
102
104
  $apply: (units) => units
103
105
  ? units
104
- .filter((unit) => Boolean(unit))
106
+ .filter(truthy_1.truthy)
105
107
  .map((unit) => (0, utils_1.visitViewUnit)(fromType, unit, visitor))
106
- .filter((unit) => (0, utils_1.isUnitExpressionValid)(unit))
108
+ .filter(utils_1.isUnitExpressionValid)
107
109
  .map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit)
108
110
  .filter((unit) => unit !== utils_1.REMOVE)
109
111
  : undefined,
@@ -255,7 +257,7 @@ const ensureAxisAndItemExpressionInvariant = (view, canGroupMetaItem) => {
255
257
  actions.forEach((action) => action());
256
258
  return view;
257
259
  };
258
- const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant, canGroupMetaItem = (metaItem) => true) => {
260
+ const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant, canGroupMetaItem = (_metaItem) => true) => {
259
261
  const visitor = {
260
262
  visitQueryExpression: (queryExpression) => (0, utils_1.deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression)(schema, queryExpression),
261
263
  visitFilter: (fromType, expression) => (0, utils_1.deleteExpressionWithNotFoundFieldsOrTypesInFilter)(schema, fromType, expression),
@@ -279,7 +281,7 @@ const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, e
279
281
  return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant(viewNew, canGroupMetaItem) : viewNew;
280
282
  };
281
283
  exports.deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = deleteExpressionWithNotFoundFieldsOrTypesInTimelineView;
282
- const fixUserSelectedUnitsInTimelineView = (schema, view, { unitDefinitions, getDefaultUnitTypeForField }) => {
284
+ const fixUserSelectedUnitsInTimelineView = (schema, view, { unitDefinitions, getDefaultUnitTypeForField, }) => {
283
285
  return visitView(view, {
284
286
  visitQueryExpression: (query) => query,
285
287
  visitExpression: (_fromType, expression) => expression,
@@ -1,6 +1,10 @@
1
- export function fixViewUnit(schema: any, fromType: any, unit: any, units: any, { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit }: {
2
- unitDefinitions: any;
3
- getDefaultUnitTypeForField: any;
4
- migrateFileCollectionUnit?: boolean | undefined;
5
- }): any;
6
- export function enableHideWhenEmptyForCheckedEditableUnit(unit: any): any;
1
+ import type { FieldObject, Schema } from "@fibery/schema";
2
+ import type { UnitDefinitions } from "./utils";
3
+ import { REMOVE } from "./utils";
4
+ import { Unit } from "@fibery/views/src/units/types";
5
+ export declare const fixViewUnit: (schema: Schema, fromType: string, unit: Unit, units: Unit[], { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit, }: {
6
+ unitDefinitions: UnitDefinitions;
7
+ getDefaultUnitTypeForField: (fieldObject: FieldObject, allowedUnits: Unit[]) => string | undefined;
8
+ migrateFileCollectionUnit?: boolean;
9
+ }) => Unit | typeof REMOVE;
10
+ export declare const enableHideWhenEmptyForCheckedEditableUnit: (unit: Unit) => Unit;
@@ -1,13 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.enableHideWhenEmptyForCheckedEditableUnit = exports.fixViewUnit = void 0;
4
- const utils_1 = require("./utils");
4
+ const utils_1 = require("@fibery/expression-utils/src/utils");
5
+ const utils_2 = require("./utils");
5
6
  const getField = (schema, fromType, field) => Object.hasOwn(schema.typeObjectsByName, fromType) &&
6
7
  Object.hasOwn(schema.typeObjectsByName[fromType].fieldObjectsByName, field)
7
8
  ? schema.typeObjectsByName[fromType].fieldObjectsByName[field]
8
9
  : undefined;
9
10
  const getFieldType = (schema, fromType, field) => getField(schema, fromType, field)?.type;
10
11
  const getFieldMeta = (schema, fromType, field) => getField(schema, fromType, field)?.rawMeta;
12
+ const getFieldByExpression = (schema, fromType, expression) => {
13
+ let currentType = fromType;
14
+ let fieldObject;
15
+ for (const part of expression) {
16
+ fieldObject = getField(schema, currentType, part);
17
+ if (!fieldObject) {
18
+ return null;
19
+ }
20
+ currentType = fieldObject.type;
21
+ }
22
+ return fieldObject ?? null;
23
+ };
11
24
  const getUnitTypeForTextField = (fieldMeta) => {
12
25
  switch (fieldMeta["ui/type"]) {
13
26
  case "email":
@@ -33,24 +46,23 @@ const migrateUnitOptsDefault = {
33
46
  migrateFileCollectionUnit: true,
34
47
  };
35
48
  const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefault) => {
36
- const { type, expression } = unit;
37
49
  const kind = unit.kind || getUnitKind(unit);
38
- if (type === "date-time") {
50
+ if (unit.type === "date-time") {
39
51
  return {
40
52
  ...unit,
41
53
  kind,
42
54
  type: "date",
43
55
  };
44
56
  }
45
- if (type === "date-time-range") {
57
+ if (unit.type === "date-time-range") {
46
58
  return {
47
59
  ...unit,
48
60
  kind,
49
61
  type: "date-range",
50
62
  };
51
63
  }
52
- if (type === "text") {
53
- const [field] = expression;
64
+ if (unit.type === "text") {
65
+ const [field] = unit.expression;
54
66
  const fieldType = getFieldType(schema, fromType, field);
55
67
  if (fieldType === "fibery/email") {
56
68
  return {
@@ -60,8 +72,8 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
60
72
  };
61
73
  }
62
74
  }
63
- if (["text", "email", "phone", "url"].includes(type)) {
64
- const [field] = expression;
75
+ if (unit.type === "text" || unit.type === "email" || unit.type === "phone" || unit.type === "url") {
76
+ const [field] = unit.expression;
65
77
  if (getFieldType(schema, fromType, field) === "fibery/text") {
66
78
  return {
67
79
  ...unit,
@@ -70,8 +82,8 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
70
82
  };
71
83
  }
72
84
  }
73
- if (type === "files-collection") {
74
- const [field] = expression;
85
+ if (unit.type === "files-collection") {
86
+ const [field] = unit.expression;
75
87
  if (getFieldType(schema, fromType, field) === "fibery/file") {
76
88
  return {
77
89
  ...unit,
@@ -80,7 +92,7 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
80
92
  };
81
93
  }
82
94
  }
83
- if (type === "avatar" && !expression) {
95
+ if (unit.type === "avatar" && !unit.expression) {
84
96
  const isAvatarExntensionEnabled = schema.typeObjectsByName[fromType]?.installedMixins.has("avatar/avatar-mixin");
85
97
  const hasAvatarExntensionField = getFieldType(schema, fromType, "avatar/avatars") === "fibery/file";
86
98
  if (isAvatarExntensionEnabled && hasAvatarExntensionField) {
@@ -91,8 +103,8 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
91
103
  };
92
104
  }
93
105
  }
94
- if (opts.migrateFileCollectionUnit && type === "collection-count") {
95
- const [field] = expression;
106
+ if (opts.migrateFileCollectionUnit && unit.type === "collection-count") {
107
+ const [field] = unit.expression;
96
108
  const fieldObject = getField(schema, fromType, field);
97
109
  if (fieldObject?.type === "fibery/file" && fieldObject?.isCollection) {
98
110
  return {
@@ -104,31 +116,40 @@ const migrateUnit = (schema, fromType, unit, units, opts = migrateUnitOptsDefaul
104
116
  }
105
117
  return { ...unit, kind };
106
118
  };
107
- const fixViewUnit = (schema, fromType, unit, units, { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit = true }) => {
119
+ const expressionFrom = (unit) => unit.expression;
120
+ const fixViewUnit = (schema, fromType, unit, units, { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit = true, }) => {
108
121
  const migrated = migrateUnit(schema, fromType, unit, units, { migrateFileCollectionUnit });
109
- const field = unit.expression?.[0];
110
- const fieldObject = getField(schema, fromType, field);
122
+ const expression = expressionFrom(unit) ?? [];
123
+ const fieldObject = getFieldByExpression(schema, fromType, expression);
111
124
  if (fieldObject) {
112
- const allowedUnits = unitDefinitions.getUnitsForField(fieldObject);
125
+ const typeObject = schema.typeObjectsByName[fromType];
126
+ const parentFieldObjects = typeObject && expression.length > 1
127
+ ? (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression }).slice(0, -1)
128
+ : [];
129
+ const allowedUnits = unitDefinitions.getUnitsForField(fieldObject, { parentFieldObjects });
113
130
  if (allowedUnits.some((u) => u.type === migrated.type)) {
114
131
  return migrated;
115
132
  }
116
133
  else {
117
134
  if (unit.checked) {
118
- const otherUnitsForField = units.filter((u) => u !== unit && u.expression && u.expression[0] === field);
135
+ const otherUnitsForField = units.filter((u) => {
136
+ const uExpression = expressionFrom(u);
137
+ return u !== unit && uExpression && expressionFrom(unit) && uExpression.join("/") === expression.join("/");
138
+ });
119
139
  const hasEnabledUnitForField = otherUnitsForField.some((u) => u.checked);
120
140
  if (hasEnabledUnitForField) {
121
- return utils_1.REMOVE;
141
+ return utils_2.REMOVE;
122
142
  }
123
143
  const defaultUnitType = getDefaultUnitTypeForField(fieldObject, allowedUnits);
124
- const defaultUnit = (defaultUnitType && otherUnitsForField.find((u) => u.type === defaultUnitType)) || otherUnitsForField[0];
144
+ const defaultUnit = (defaultUnitType && otherUnitsForField.find((u) => u.type === defaultUnitType)) ||
145
+ otherUnitsForField[0];
125
146
  if (defaultUnit) {
126
147
  defaultUnit.checked = true;
127
- return utils_1.REMOVE;
148
+ return utils_2.REMOVE;
128
149
  }
129
150
  }
130
151
  else {
131
- return utils_1.REMOVE;
152
+ return utils_2.REMOVE;
132
153
  }
133
154
  }
134
155
  }
@@ -1,17 +1,64 @@
1
- export const REMOVE: unique symbol;
2
- export function deleteExpressionWithNotFoundFieldsOrTypesInFilter(schema: any, fromType: any, filter: any): any;
3
- export function deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema: any, queryExpression: any): Partial<any> | null;
4
- export function replaceNamesWithIdsInExpression(schema: any, fromType: any, expression: any): any;
5
- export function replaceIdsWithNamesInExpression(schema: any, fromTypeId: any, expression: any): any;
6
- export function visitViewUnit(fromType: any, unit: any, visitor: any): any;
7
- export function visitContextExpression(fromType: any, contextExpression: any, visitor: any): any;
8
- export function replaceIdsWithNamesInQueryExpression(schema: any, queryExpression: any): any;
9
- export function replaceIdsWithNamesInFilter(schema: any, fromType: any, filter: any): any;
10
- export function replaceNamesWithIdsInFilter(schema: any, fromType: any, filter: any): any;
11
- export function replaceNamesWithIdsInQueryExpression(schema: any, queryExpression: any): any;
12
- export function deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema: any, fromType: any, expression: any): any;
13
- export function resetContextExpressionIfBroken(schema: any, fromType: any, expression: any, defaultExpression: any): any;
14
- export function isUnitExpressionValid(unit: any): boolean;
15
- export function getFieldObjectsById(smartFolder: any, schema: any): any;
16
- export function replaceIdsWithNamesInUnitGroupKey(unitGroupKey: any, fieldObjectsById: any): any;
17
- export function replaceNamesWithIdsInUnitGroupKey(unitGroupKey: any, schema: any): any;
1
+ import type { Expression, Query } from "@fibery/expression-utils/src/types";
2
+ import type { FieldObject, Schema } from "@fibery/schema";
3
+ import { Unit } from "@fibery/views/src/units/types";
4
+ export declare const REMOVE: unique symbol;
5
+ export declare const skipRemove: (unit: Unit | typeof REMOVE) => unit is Unit;
6
+ export type ViewVisitor = {
7
+ visitExpression: (fromType: string, expression: Expression) => Expression | null;
8
+ visitFilter: (fromType: string, filter: ViewFilter | null) => ViewFilter | null;
9
+ visitQueryExpression: (query: Query) => Query | null;
10
+ visitViewUnit?: (fromType: string, unit: Unit, units: Unit[]) => Unit | typeof REMOVE;
11
+ visitContextExpression?: (fromType: string, expression: Expression) => Expression;
12
+ visitGroupByExpression?: (groupBy: Record<string, unknown>, fromType: string, removedItems?: number[]) => Record<string, unknown> | null;
13
+ visitEnums?: (enums: Record<string, unknown>) => Record<string, unknown> | null;
14
+ visitUnitGroupKey?: (key: string) => string;
15
+ };
16
+ export type UnitDefinitions = {
17
+ getUnitsForField: (fieldObject: FieldObject, options?: {
18
+ parentFieldObjects?: FieldObject[];
19
+ }) => Unit[];
20
+ };
21
+ export type ViewRecord = Record<string, unknown>;
22
+ type ViewFilterLeaf = {
23
+ kind: string;
24
+ value: {
25
+ expression: Expression | null;
26
+ [k: string]: unknown;
27
+ };
28
+ };
29
+ type ViewFilterGroup = {
30
+ kind: "group";
31
+ value: ViewFilter[];
32
+ };
33
+ export type ViewFilter = ViewFilterLeaf | ViewFilterGroup;
34
+ export declare const deleteExpressionWithNotFoundFieldsOrTypesInFilter: (schema: Schema, fromType: string, filter: ViewFilter) => ViewFilter | null;
35
+ export declare const deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression: (schema: Schema, queryExpression: Query) => Query | null;
36
+ export declare const replaceNamesWithIdsInExpression: (schema: Schema, fromType: string, expression: Expression) => any;
37
+ export declare const replaceIdsWithNamesInExpression: (schema: Schema, fromTypeId: string, expression: Expression) => any;
38
+ export declare const visitViewUnit: (fromType: string, unit: Unit, visitor: Pick<ViewVisitor, "visitExpression">) => Unit;
39
+ export declare const visitContextExpression: (fromType: string, contextExpression: Expression | null | undefined, visitor: Pick<ViewVisitor, "visitExpression" | "visitContextExpression">) => string | Expression[] | null | undefined;
40
+ export declare const replaceIdsWithNamesInQueryExpression: (schema: Schema, queryExpression: Query) => {
41
+ "q/order-by"?: any;
42
+ "q/where"?: any;
43
+ "q/from": string;
44
+ "q/select"?: Expression | import("@fibery/expression-utils/src/types").Select;
45
+ "q/offset"?: number;
46
+ "q/limit"?: import("@fibery/expression-utils/src/types").QueryLimit;
47
+ };
48
+ export declare const replaceIdsWithNamesInFilter: (schema: Schema, fromType: string, filter: ViewFilter | null) => ViewFilter | null;
49
+ export declare const replaceNamesWithIdsInFilter: (schema: Schema, fromType: string, filter: ViewFilter | null) => ViewFilter | null;
50
+ export declare const replaceNamesWithIdsInQueryExpression: (schema: Schema, queryExpression: Query) => {
51
+ "q/order-by"?: any;
52
+ "q/where"?: any;
53
+ "q/from": string;
54
+ "q/select"?: Expression | import("@fibery/expression-utils/src/types").Select;
55
+ "q/offset"?: number;
56
+ "q/limit"?: import("@fibery/expression-utils/src/types").QueryLimit;
57
+ };
58
+ export declare const deleteExpressionWithNotFoundFieldsOrTypesInExpression: (schema: Schema, fromType: string, expression: Expression) => any;
59
+ export declare const resetContextExpressionIfBroken: (schema: Schema, fromType: string, expression: Expression, defaultExpression: Expression) => any;
60
+ export declare const isUnitExpressionValid: (unit: Record<string, unknown>) => boolean;
61
+ export declare const getFieldObjectsById: (smartFolder: Record<string, unknown>, schema: Schema) => Record<string, FieldObject>;
62
+ export declare const replaceIdsWithNamesInUnitGroupKey: (unitGroupKey: string, fieldObjectsById: Record<string, FieldObject>) => string;
63
+ export declare const replaceNamesWithIdsInUnitGroupKey: (unitGroupKey: string, schema: Schema) => string;
64
+ export {};
@@ -3,12 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.replaceNamesWithIdsInUnitGroupKey = exports.replaceIdsWithNamesInUnitGroupKey = exports.getFieldObjectsById = exports.isUnitExpressionValid = exports.resetContextExpressionIfBroken = exports.deleteExpressionWithNotFoundFieldsOrTypesInExpression = exports.replaceNamesWithIdsInQueryExpression = exports.replaceNamesWithIdsInFilter = exports.replaceIdsWithNamesInFilter = exports.replaceIdsWithNamesInQueryExpression = exports.visitContextExpression = exports.visitViewUnit = exports.replaceIdsWithNamesInExpression = exports.replaceNamesWithIdsInExpression = exports.deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = exports.deleteExpressionWithNotFoundFieldsOrTypesInFilter = exports.REMOVE = void 0;
6
+ exports.replaceNamesWithIdsInUnitGroupKey = exports.replaceIdsWithNamesInUnitGroupKey = exports.getFieldObjectsById = exports.isUnitExpressionValid = exports.resetContextExpressionIfBroken = exports.deleteExpressionWithNotFoundFieldsOrTypesInExpression = exports.replaceNamesWithIdsInQueryExpression = exports.replaceNamesWithIdsInFilter = exports.replaceIdsWithNamesInFilter = exports.replaceIdsWithNamesInQueryExpression = exports.visitContextExpression = exports.visitViewUnit = exports.replaceIdsWithNamesInExpression = exports.replaceNamesWithIdsInExpression = exports.deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = exports.deleteExpressionWithNotFoundFieldsOrTypesInFilter = exports.skipRemove = exports.REMOVE = void 0;
7
7
  const visitors_1 = require("@fibery/expression-utils/src/visitors");
8
8
  const pickBy_1 = __importDefault(require("lodash/pickBy"));
9
+ const truthy_1 = require("../truthy");
9
10
  // Return this symbol from a visitor callback to remove the node from the
10
11
  // output. Not supported in all places, add support as needed.
11
12
  exports.REMOVE = Symbol("remove");
13
+ const skipRemove = (unit) => unit !== exports.REMOVE;
14
+ exports.skipRemove = skipRemove;
12
15
  function visitDeleteExpressionInFilterGroup(filter, visitExpression) {
13
16
  if (filter.kind !== "group") {
14
17
  return null;
@@ -18,19 +21,20 @@ function visitDeleteExpressionInFilterGroup(filter, visitExpression) {
18
21
  if (nestedFilter.kind === "group") {
19
22
  return visitFilterGroup(nestedFilter, visitExpression);
20
23
  }
21
- const expression = nestedFilter.value.expression ? visitExpression(nestedFilter.value.expression) : null;
24
+ const leaf = nestedFilter;
25
+ const expression = leaf.value.expression ? visitExpression(leaf.value.expression) : null;
22
26
  if (!expression) {
23
27
  return null;
24
28
  }
25
29
  return {
26
- ...nestedFilter,
30
+ ...leaf,
27
31
  value: {
28
- ...nestedFilter.value,
32
+ ...leaf.value,
29
33
  expression: expression,
30
34
  },
31
35
  };
32
36
  })
33
- .filter(Boolean);
37
+ .filter(truthy_1.truthy);
34
38
  if (value.length === 0) {
35
39
  return null;
36
40
  }
@@ -81,16 +85,15 @@ const replaceIdsWithNamesInExpression = (schema, fromTypeId, expression) => {
81
85
  };
82
86
  exports.replaceIdsWithNamesInExpression = replaceIdsWithNamesInExpression;
83
87
  const visitViewUnit = (fromType, unit, visitor) => {
88
+ if (unit.kind === "user-button") {
89
+ return unit;
90
+ }
84
91
  const { expression } = unit;
85
- if (expression) {
86
- return {
87
- ...unit,
88
- ...{
89
- expression: visitor.visitExpression(fromType, expression),
90
- },
91
- };
92
+ if (!expression) {
93
+ return unit;
92
94
  }
93
- return unit;
95
+ // visitExpression preserves string[] shape; null results are filtered by isUnitExpressionValid downstream
96
+ return { ...unit, expression: visitor.visitExpression(fromType, expression) };
94
97
  };
95
98
  exports.visitViewUnit = visitViewUnit;
96
99
  const visitContextExpression = (fromType, contextExpression, visitor) => {
@@ -122,21 +125,23 @@ const replaceIdsWithNamesInQueryExpression = (schema, queryExpression) => {
122
125
  return queryExpression;
123
126
  };
124
127
  exports.replaceIdsWithNamesInQueryExpression = replaceIdsWithNamesInQueryExpression;
125
- function visitFilterGroup(filter, visitExpression, type) {
128
+ function visitFilterGroup(filter, visitExpression, _type) {
126
129
  if (filter.kind !== "group") {
127
130
  return null;
128
131
  }
132
+ const group = filter;
129
133
  return {
130
- ...filter,
131
- value: filter.value.map((nestedFilter) => {
134
+ ...group,
135
+ value: group.value.map((nestedFilter) => {
132
136
  if (nestedFilter.kind === "group") {
133
137
  return visitFilterGroup(nestedFilter, visitExpression);
134
138
  }
139
+ const leaf = nestedFilter;
135
140
  return {
136
- ...nestedFilter,
141
+ ...leaf,
137
142
  value: {
138
- ...nestedFilter.value,
139
- expression: nestedFilter.value.expression ? visitExpression(nestedFilter.value.expression) : null,
143
+ ...leaf.value,
144
+ expression: leaf.value.expression ? visitExpression(leaf.value.expression) : null,
140
145
  },
141
146
  };
142
147
  }),
@@ -203,7 +208,8 @@ const isUnitExpressionValid = (unit) => {
203
208
  };
204
209
  exports.isUnitExpressionValid = isUnitExpressionValid;
205
210
  const getFieldObjectsById = (smartFolder, schema) => {
206
- const types = smartFolder["fibery/meta"].items.map((item) => item.query["q/from"]);
211
+ const meta = smartFolder["fibery/meta"];
212
+ const types = meta.items.map((item) => item.query["q/from"]);
207
213
  return types.reduce((acc, type) => {
208
214
  if (!Object.hasOwn(schema.typeObjectsById, type)) {
209
215
  return acc;
@@ -0,0 +1 @@
1
+ export declare const truthy: <T>(x: T | null | undefined | false) => x is T;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.truthy = void 0;
4
+ const truthy = (x) => {
5
+ return Boolean(x);
6
+ };
7
+ exports.truthy = truthy;
@@ -10,6 +10,7 @@ const select_1 = require("@fibery/query-utils/src/select");
10
10
  const get_export_value_1 = require("../unit-utils/get-export-value");
11
11
  const avatar_1 = require("../field-utils/avatar");
12
12
  const common_1 = require("../unit-utils/common");
13
+ const get_field_label_1 = require("../unit-utils/get-field-label");
13
14
  const type = "avatar-collection";
14
15
  exports.AvatarCollection = {
15
16
  type,
@@ -18,29 +19,33 @@ exports.AvatarCollection = {
18
19
  return (0, common_1.canEditFieldExpression)(typeObject, expression);
19
20
  },
20
21
  getLabel({ typeObject, unit }) {
21
- const { expression } = unit;
22
- const fieldObject = (0, utils_1.getFieldObjectByFieldExpression)({ typeObject, expression });
23
- return `Avatar of ${fieldObject.title}`;
22
+ return `Avatar of ${(0, get_field_label_1.getFieldLabel)({ typeObject, unit })}`;
24
23
  },
25
24
  makeUnit: (0, common_1.makeUnitMethod)(type),
26
25
  getQuerySelect({ typeObject, unit: { expression } }) {
27
- const [userCollectionField] = expression;
28
- const userCollectionFieldObject = typeObject.fieldObjectsByName[userCollectionField];
29
- return {
30
- [userCollectionField]: {
31
- "q/from": [userCollectionField],
32
- "q/select": (0, select_1.mergeDenormalizedSelects)((0, compact_1.default)([
33
- (0, select_1.toSelectMapClause)([
34
- userCollectionFieldObject.typeObject.idField,
35
- userCollectionFieldObject.typeObject.titleField,
36
- ]),
37
- (0, avatar_1.getAvatarSelectQuery)({
38
- typeObject: userCollectionFieldObject.typeObject,
39
- }),
40
- ])),
41
- "q/limit": "q/no-limit",
42
- },
26
+ const fieldObjects = (0, utils_1.getFieldObjectsByFieldExpression)({ typeObject, expression });
27
+ const terminalFieldObject = fieldObjects[fieldObjects.length - 1];
28
+ const collectionSubQuery = {
29
+ "q/from": expression,
30
+ "q/select": (0, select_1.mergeDenormalizedSelects)((0, compact_1.default)([
31
+ (0, select_1.toSelectMapClause)([terminalFieldObject.typeObject.idField, terminalFieldObject.typeObject.titleField]),
32
+ (0, avatar_1.getAvatarSelectQuery)({ typeObject: terminalFieldObject.typeObject }),
33
+ ])),
34
+ "q/limit": "q/no-limit",
43
35
  };
36
+ return [...expression].reverse().reduce((inner, field, reversedIndex) => {
37
+ const originalIndex = expression.length - 1 - reversedIndex;
38
+ const isTerminal = originalIndex === expression.length - 1;
39
+ if (!isTerminal) {
40
+ const pathToField = expression.slice(0, originalIndex + 1);
41
+ const { idField } = fieldObjects[originalIndex].typeObject;
42
+ const innerForField = idField
43
+ ? { [idField]: [...pathToField, idField], ...inner }
44
+ : { ...inner };
45
+ return { [field]: innerForField };
46
+ }
47
+ return { [field]: inner };
48
+ }, collectionSubQuery);
44
49
  },
45
50
  calculateErrors: common_1.calculateUnitExpressionErrors,
46
51
  getExportValue: get_export_value_1.getReferenceCollectionExportValue,