@nocobase/client-v2 2.1.0-alpha.40 → 2.1.0-alpha.45

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 (278) hide show
  1. package/es/Application.d.ts +7 -0
  2. package/es/BaseApplication.d.ts +13 -0
  3. package/es/RouterManager.d.ts +1 -0
  4. package/es/collection-field-interface/CollectionFieldInterface.d.ts +51 -15
  5. package/es/collection-field-interface/CollectionFieldInterfaceManager.d.ts +82 -3
  6. package/es/collection-manager/field-configure.d.ts +80 -0
  7. package/es/collection-manager/field-validation.d.ts +43 -0
  8. package/es/collection-manager/filter-operators/index.d.ts +46 -0
  9. package/es/collection-manager/filter-operators/operators.d.ts +30 -0
  10. package/es/collection-manager/interfaces/checkbox.d.ts +1 -41
  11. package/es/collection-manager/interfaces/checkboxGroup.d.ts +12 -44
  12. package/es/collection-manager/interfaces/collection.d.ts +12 -51
  13. package/es/collection-manager/interfaces/color.d.ts +1 -16
  14. package/es/collection-manager/interfaces/createdAt.d.ts +1 -44
  15. package/es/collection-manager/interfaces/createdBy.d.ts +0 -4
  16. package/es/collection-manager/interfaces/dateOnly.d.ts +7 -44
  17. package/es/collection-manager/interfaces/datetime.d.ts +1 -44
  18. package/es/collection-manager/interfaces/datetimeNoTz.d.ts +1 -44
  19. package/es/collection-manager/interfaces/email.d.ts +1 -29
  20. package/es/collection-manager/interfaces/id.d.ts +1 -16
  21. package/es/collection-manager/interfaces/index.d.ts +2 -3
  22. package/es/collection-manager/interfaces/input.d.ts +1 -102
  23. package/es/collection-manager/interfaces/integer.d.ts +1 -95
  24. package/es/collection-manager/interfaces/json.d.ts +16 -7
  25. package/es/collection-manager/interfaces/m2m.d.ts +11 -19
  26. package/es/collection-manager/interfaces/m2o.d.ts +11 -19
  27. package/es/collection-manager/interfaces/markdown.d.ts +1 -63
  28. package/es/collection-manager/interfaces/multipleSelect.d.ts +12 -44
  29. package/es/collection-manager/interfaces/nanoid.d.ts +1 -34
  30. package/es/collection-manager/interfaces/number.d.ts +1 -87
  31. package/es/collection-manager/interfaces/o2m.d.ts +12 -24
  32. package/es/collection-manager/interfaces/obo.d.ts +207 -0
  33. package/es/collection-manager/interfaces/oho.d.ts +207 -0
  34. package/es/collection-manager/interfaces/password.d.ts +1 -56
  35. package/es/collection-manager/interfaces/percent.d.ts +1 -84
  36. package/es/collection-manager/interfaces/phone.d.ts +1 -25
  37. package/es/collection-manager/interfaces/properties/index.d.ts +0 -28
  38. package/es/collection-manager/interfaces/radioGroup.d.ts +1 -29
  39. package/es/collection-manager/interfaces/richText.d.ts +1 -63
  40. package/es/collection-manager/interfaces/select.d.ts +12 -44
  41. package/es/collection-manager/interfaces/snowflake-id.d.ts +1 -34
  42. package/es/collection-manager/interfaces/tableoid.d.ts +1 -10
  43. package/es/collection-manager/interfaces/textarea.d.ts +1 -51
  44. package/es/collection-manager/interfaces/time.d.ts +1 -16
  45. package/es/collection-manager/interfaces/types.d.ts +3 -12
  46. package/es/collection-manager/interfaces/unixTimestamp.d.ts +1 -44
  47. package/es/collection-manager/interfaces/updatedAt.d.ts +1 -44
  48. package/es/collection-manager/interfaces/updatedBy.d.ts +0 -4
  49. package/es/collection-manager/interfaces/url.d.ts +1 -20
  50. package/es/collection-manager/interfaces/uuid.d.ts +1 -34
  51. package/es/collection-manager/template-fields.d.ts +53 -0
  52. package/es/components/KeepAlive.d.ts +22 -0
  53. package/es/components/RouterBridge.d.ts +9 -0
  54. package/es/components/form/DialogFormLayout.d.ts +5 -29
  55. package/es/components/form/VariableInput.d.ts +53 -2
  56. package/es/components/form/filter/CollectionFilter.d.ts +49 -0
  57. package/es/components/form/filter/CollectionFilterItem.d.ts +49 -0
  58. package/es/components/form/filter/DateFilterDynamicComponent.d.ts +57 -0
  59. package/es/components/form/filter/FilterValueInput.d.ts +29 -0
  60. package/es/components/form/filter/index.d.ts +11 -0
  61. package/es/components/form/filter/useFilterActionProps.d.ts +96 -0
  62. package/es/components/form/index.d.ts +1 -0
  63. package/es/data-source/ExtendCollectionsProvider.d.ts +50 -0
  64. package/es/data-source/index.d.ts +9 -0
  65. package/es/flow/FlowPage.d.ts +2 -1
  66. package/es/flow/admin-shell/AdminLayoutRouteCoordinator.d.ts +8 -40
  67. package/es/flow/admin-shell/BaseLayoutModel.d.ts +89 -0
  68. package/es/flow/admin-shell/BaseLayoutRouteCoordinator.d.ts +74 -0
  69. package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +12 -0
  70. package/es/flow/admin-shell/admin-layout/AdminLayoutModel.d.ts +7 -92
  71. package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +11 -0
  72. package/es/flow/admin-shell/admin-layout/index.d.ts +3 -0
  73. package/es/flow/admin-shell/admin-layout/useApplications.d.ts +3 -2
  74. package/es/flow/admin-shell/useAdminLayoutRoutePage.d.ts +2 -2
  75. package/es/flow/admin-shell/useLayoutRoutePage.d.ts +23 -0
  76. package/es/flow/components/FlowRoute.d.ts +10 -1
  77. package/es/flow/components/filter/index.d.ts +2 -0
  78. package/es/flow/components/filter/useFilterOptions.d.ts +66 -0
  79. package/es/flow/index.d.ts +4 -0
  80. package/es/flow/models/base/PageModel/PageModel.d.ts +3 -1
  81. package/es/flow/models/blocks/assign-form/assignFieldValuesFlow.d.ts +84 -0
  82. package/es/flow/models/blocks/assign-form/index.d.ts +1 -0
  83. package/es/flow/models/blocks/form/FormActionGroupModel.d.ts +1 -0
  84. package/es/flow/models/blocks/form/FormActionModel.d.ts +9 -2
  85. package/es/flow/models/blocks/table/TableBlockModel.d.ts +10 -0
  86. package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.d.ts +1 -1
  87. package/es/flow-compat/passwordUtils.d.ts +1 -1
  88. package/es/index.d.ts +6 -0
  89. package/es/index.mjs +552 -459
  90. package/es/layout-manager/LayoutContentRoute.d.ts +14 -0
  91. package/es/layout-manager/LayoutManager.d.ts +22 -0
  92. package/es/layout-manager/LayoutRoute.d.ts +14 -0
  93. package/es/layout-manager/index.d.ts +13 -0
  94. package/es/layout-manager/types.d.ts +20 -0
  95. package/es/layout-manager/utils.d.ts +14 -0
  96. package/es/nocobase-buildin-plugin/index.d.ts +3 -10
  97. package/es/settings-center/index.d.ts +1 -1
  98. package/es/settings-center/plugin-manager/BulkEnableButton.d.ts +15 -0
  99. package/es/settings-center/plugin-manager/PluginCard.d.ts +15 -0
  100. package/es/settings-center/plugin-manager/PluginDetail.d.ts +16 -0
  101. package/es/settings-center/{PluginManagerPage.d.ts → plugin-manager/index.d.ts} +1 -7
  102. package/es/settings-center/plugin-manager/types.d.ts +34 -0
  103. package/lib/index.js +552 -459
  104. package/package.json +8 -7
  105. package/src/Application.tsx +51 -12
  106. package/src/BaseApplication.tsx +32 -0
  107. package/src/PluginSettingsManager.ts +1 -1
  108. package/src/RouterManager.tsx +17 -1
  109. package/src/__tests__/PluginSettingsManager.test.ts +41 -2
  110. package/src/__tests__/app.test.tsx +17 -1
  111. package/src/__tests__/globalDeps.test.ts +1 -0
  112. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +45 -2
  113. package/src/__tests__/plugin-manager.test.tsx +177 -0
  114. package/src/__tests__/settings-center.test.tsx +24 -2
  115. package/src/collection-field-interface/CollectionFieldInterface.ts +71 -77
  116. package/src/collection-field-interface/CollectionFieldInterfaceManager.ts +201 -4
  117. package/src/collection-manager/field-configure.ts +548 -0
  118. package/src/collection-manager/field-validation.ts +195 -0
  119. package/src/collection-manager/filter-operators/index.ts +176 -0
  120. package/src/collection-manager/{interfaces/properties → filter-operators}/operators.ts +24 -13
  121. package/src/collection-manager/interfaces/checkbox.ts +2 -9
  122. package/src/collection-manager/interfaces/checkboxGroup.ts +2 -10
  123. package/src/collection-manager/interfaces/collection.ts +2 -15
  124. package/src/collection-manager/interfaces/color.ts +2 -2
  125. package/src/collection-manager/interfaces/createdAt.ts +2 -2
  126. package/src/collection-manager/interfaces/createdBy.ts +1 -12
  127. package/src/collection-manager/interfaces/dateOnly.ts +8 -2
  128. package/src/collection-manager/interfaces/datetime.ts +2 -2
  129. package/src/collection-manager/interfaces/datetimeNoTz.ts +2 -2
  130. package/src/collection-manager/interfaces/email.ts +2 -9
  131. package/src/collection-manager/interfaces/id.ts +1 -2
  132. package/src/collection-manager/interfaces/index.ts +2 -3
  133. package/src/collection-manager/interfaces/input.ts +2 -133
  134. package/src/collection-manager/interfaces/integer.ts +2 -71
  135. package/src/collection-manager/interfaces/json.tsx +17 -11
  136. package/src/collection-manager/interfaces/m2m.tsx +0 -21
  137. package/src/collection-manager/interfaces/m2o.tsx +0 -22
  138. package/src/collection-manager/interfaces/markdown.ts +2 -51
  139. package/src/collection-manager/interfaces/multipleSelect.ts +2 -14
  140. package/src/collection-manager/interfaces/nanoid.ts +2 -2
  141. package/src/collection-manager/interfaces/number.ts +2 -85
  142. package/src/collection-manager/interfaces/o2m.tsx +1 -22
  143. package/src/collection-manager/interfaces/obo.tsx +145 -0
  144. package/src/collection-manager/interfaces/oho.tsx +145 -0
  145. package/src/collection-manager/interfaces/password.ts +2 -44
  146. package/src/collection-manager/interfaces/percent.ts +2 -74
  147. package/src/collection-manager/interfaces/phone.ts +2 -2
  148. package/src/collection-manager/interfaces/properties/index.ts +0 -133
  149. package/src/collection-manager/interfaces/radioGroup.ts +2 -2
  150. package/src/collection-manager/interfaces/richText.ts +2 -51
  151. package/src/collection-manager/interfaces/select.ts +2 -14
  152. package/src/collection-manager/interfaces/snowflake-id.ts +2 -2
  153. package/src/collection-manager/interfaces/tableoid.ts +1 -2
  154. package/src/collection-manager/interfaces/textarea.ts +2 -51
  155. package/src/collection-manager/interfaces/time.ts +2 -2
  156. package/src/collection-manager/interfaces/types.ts +4 -12
  157. package/src/collection-manager/interfaces/unixTimestamp.tsx +2 -2
  158. package/src/collection-manager/interfaces/updatedAt.ts +2 -2
  159. package/src/collection-manager/interfaces/updatedBy.ts +1 -12
  160. package/src/collection-manager/interfaces/url.ts +2 -4
  161. package/src/collection-manager/interfaces/uuid.ts +2 -2
  162. package/src/collection-manager/template-fields.ts +109 -0
  163. package/src/components/KeepAlive.tsx +131 -0
  164. package/src/components/README.md +90 -6
  165. package/src/components/README.zh-CN.md +90 -7
  166. package/src/components/RouterBridge.tsx +28 -4
  167. package/src/components/__tests__/KeepAlive.test.tsx +63 -0
  168. package/src/components/__tests__/RouterBridge.test.tsx +27 -0
  169. package/src/components/form/DialogFormLayout.tsx +5 -29
  170. package/src/components/form/VariableInput.tsx +101 -28
  171. package/src/components/form/__tests__/VariableInput.test.ts +85 -0
  172. package/src/components/form/filter/CollectionFilter.tsx +111 -0
  173. package/src/components/form/filter/CollectionFilterItem.tsx +184 -0
  174. package/src/components/form/filter/DateFilterDynamicComponent.tsx +283 -0
  175. package/src/components/form/filter/FilterValueInput.tsx +198 -0
  176. package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +247 -0
  177. package/src/components/form/filter/__tests__/DateFilterDynamicComponent.test.tsx +148 -0
  178. package/src/components/form/filter/__tests__/FilterValueInput.test.tsx +243 -0
  179. package/src/components/form/filter/__tests__/compileFilterGroup.test.ts +146 -0
  180. package/src/components/form/filter/index.ts +13 -0
  181. package/src/components/form/filter/useFilterActionProps.ts +203 -0
  182. package/src/components/form/index.tsx +1 -0
  183. package/src/data-source/ExtendCollectionsProvider.tsx +144 -0
  184. package/src/data-source/__tests__/ExtendCollectionsProvider.test.tsx +264 -0
  185. package/src/data-source/index.ts +10 -0
  186. package/src/flow/FlowPage.tsx +35 -7
  187. package/src/flow/__tests__/FlowPage.test.tsx +79 -0
  188. package/src/flow/__tests__/FlowRoute.test.tsx +529 -2
  189. package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +191 -0
  190. package/src/flow/actions/__tests__/openView.subModelKey.test.tsx +33 -0
  191. package/src/flow/actions/aclCheck.tsx +4 -0
  192. package/src/flow/actions/aclCheckRefresh.tsx +4 -0
  193. package/src/flow/actions/dateTimeFormat.tsx +12 -8
  194. package/src/flow/actions/linkageRules.tsx +122 -0
  195. package/src/flow/actions/openView.tsx +28 -4
  196. package/src/flow/admin-shell/AdminLayoutRouteCoordinator.ts +11 -329
  197. package/src/flow/admin-shell/BaseLayoutModel.tsx +455 -0
  198. package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +502 -0
  199. package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +547 -3
  200. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +35 -7
  201. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +160 -0
  202. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +0 -12
  203. package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +28 -201
  204. package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +11 -2
  205. package/src/flow/admin-shell/admin-layout/AppListRender.tsx +139 -0
  206. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +1 -26
  207. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +149 -27
  208. package/src/flow/admin-shell/admin-layout/index.ts +3 -0
  209. package/src/flow/admin-shell/admin-layout/useApplications.tsx +34 -1
  210. package/src/flow/admin-shell/useAdminLayoutRoutePage.ts +10 -26
  211. package/src/flow/admin-shell/useLayoutRoutePage.ts +61 -0
  212. package/src/flow/components/AdminLayout.tsx +4 -154
  213. package/src/flow/components/FlowRoute.tsx +105 -15
  214. package/src/flow/components/filter/index.ts +3 -0
  215. package/src/flow/components/filter/useFilterOptions.ts +102 -0
  216. package/src/flow/index.ts +4 -0
  217. package/src/flow/models/actions/UpdateRecordActionModel.tsx +14 -95
  218. package/src/flow/models/actions/UpdateRecordActionUtils.ts +4 -7
  219. package/src/flow/models/actions/__tests__/AssignFormRefill.test.ts +26 -1
  220. package/src/flow/models/base/ActionModel.tsx +8 -1
  221. package/src/flow/models/base/PageModel/PageModel.tsx +51 -18
  222. package/src/flow/models/base/PageModel/RootPageModel.tsx +6 -13
  223. package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +102 -1
  224. package/src/flow/models/base/RouteModel.tsx +1 -1
  225. package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +63 -2
  226. package/src/flow/models/blocks/assign-form/assignFieldValuesFlow.tsx +206 -0
  227. package/src/flow/models/blocks/assign-form/index.ts +1 -0
  228. package/src/flow/models/blocks/form/FormActionGroupModel.tsx +14 -0
  229. package/src/flow/models/blocks/form/FormActionModel.tsx +30 -3
  230. package/src/flow/models/blocks/form/FormItemModel.tsx +8 -1
  231. package/src/flow/models/blocks/form/__tests__/FormActionGroupModel.test.ts +46 -0
  232. package/src/flow/models/blocks/form/__tests__/submitHandler.test.ts +71 -0
  233. package/src/flow/models/blocks/form/submitHandler.ts +8 -1
  234. package/src/flow/models/blocks/form/submitValues.ts +4 -1
  235. package/src/flow/models/blocks/table/TableBlockModel.tsx +118 -16
  236. package/src/flow/models/blocks/table/__tests__/TableBlockModel.rowSelection.test.tsx +114 -0
  237. package/src/flow/models/fields/AssociationFieldModel/SubFormFieldModel.tsx +7 -1
  238. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.tsx +1 -1
  239. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.tsx +6 -5
  240. package/src/flow/models/fields/ClickableFieldModel.tsx +9 -1
  241. package/src/flow/models/fields/CollectionSelectorFieldModel.tsx +8 -2
  242. package/src/flow/models/fields/DisplayEnumFieldModel.tsx +8 -2
  243. package/src/flow/models/fields/DisplayTimeFieldModel.tsx +1 -1
  244. package/src/flow/models/fields/TimeFieldModel.tsx +1 -1
  245. package/src/flow/models/fields/__tests__/TimeFieldModel.test.tsx +61 -0
  246. package/src/flow/models/fields/mobile-components/MobileDatePicker.tsx +19 -3
  247. package/src/flow/models/fields/mobile-components/__tests__/MobileDatePicker.test.tsx +94 -0
  248. package/src/flow/models/topbar/TopbarActionModel.tsx +1 -1
  249. package/src/flow/utils/__tests__/dateTimeFormat.test.ts +91 -0
  250. package/src/index.ts +6 -0
  251. package/src/layout-manager/LayoutContentRoute.tsx +90 -0
  252. package/src/layout-manager/LayoutManager.tsx +185 -0
  253. package/src/layout-manager/LayoutRoute.tsx +138 -0
  254. package/src/layout-manager/__tests__/LayoutManager.test.tsx +335 -0
  255. package/src/layout-manager/__tests__/LayoutRoute.test.tsx +473 -0
  256. package/src/layout-manager/index.ts +14 -0
  257. package/src/layout-manager/types.ts +22 -0
  258. package/src/layout-manager/utils.ts +37 -0
  259. package/src/nocobase-buildin-plugin/index.tsx +69 -67
  260. package/src/nocobase-buildin-plugin/plugins/LocalePlugin.ts +1 -0
  261. package/src/settings-center/index.ts +1 -1
  262. package/src/settings-center/plugin-manager/BulkEnableButton.tsx +111 -0
  263. package/src/settings-center/plugin-manager/PluginCard.tsx +270 -0
  264. package/src/settings-center/plugin-manager/PluginDetail.tsx +195 -0
  265. package/src/settings-center/plugin-manager/index.tsx +254 -0
  266. package/src/settings-center/plugin-manager/types.ts +35 -0
  267. package/src/settings-center/utils.tsx +8 -1
  268. package/src/theme/__tests__/globalStyles.test.ts +24 -0
  269. package/src/theme/globalStyles.ts +10 -0
  270. package/src/utils/globalDeps.ts +2 -0
  271. package/es/collection-manager/interfaces/linkTo.d.ts +0 -90
  272. package/es/collection-manager/interfaces/o2o.d.ts +0 -621
  273. package/es/collection-manager/interfaces/properties/operators.d.ts +0 -294
  274. package/es/collection-manager/interfaces/subTable.d.ts +0 -172
  275. package/src/collection-manager/interfaces/linkTo.ts +0 -120
  276. package/src/collection-manager/interfaces/o2o.tsx +0 -561
  277. package/src/collection-manager/interfaces/subTable.ts +0 -218
  278. package/src/settings-center/PluginManagerPage.tsx +0 -162
@@ -25,28 +25,75 @@ import { TextAreaWithContextSelector } from '../../flow/components/TextAreaWithC
25
25
  * stored values round-trip to a labelled pill instead of falling back to a
26
26
  * raw `{{…}}` literal.
27
27
  */
28
- const VARIABLE_EXPR_RE = /^\{\{\s*(.+?)\s*\}\}$/;
29
-
30
- export function parseVariablePath(value?: string): string[] | undefined {
31
- if (typeof value !== 'string') return undefined;
32
- const match = value.trim().match(VARIABLE_EXPR_RE);
33
- if (!match) return undefined;
34
- let pathString = match[1];
35
- // Backwards-compat: accept the legacy `ctx.` prefix so values produced by
36
- // pre-fix versions of the picker still resolve to a labelled pill.
37
- if (pathString === 'ctx') return [];
38
- if (pathString.startsWith('ctx.')) pathString = pathString.slice(4);
39
- return pathString.split('.');
28
+
29
+ /**
30
+ * Variable delimiters: opening + closing tokens. Default `['{{', '}}']`
31
+ * matches NocoBase server template convention (Handlebars HTML-escaped
32
+ * output). Pass `['{{{', '}}}']` to switch to Handlebars' raw/unescaped
33
+ * form — required for fields whose content is rendered as HTML (e.g.
34
+ * in-app message body) so the variable expansion bypasses HTML escaping.
35
+ *
36
+ * Restrict to literal-token pairs, since the regex builder escapes them
37
+ * verbatim.
38
+ */
39
+ export type VariableDelimiters = readonly [string, string];
40
+
41
+ const DEFAULT_DELIMITERS: VariableDelimiters = ['{{', '}}'];
42
+
43
+ function escapeForRegExp(s: string): string {
44
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
40
45
  }
41
46
 
42
- export function formatVariablePath(meta?: MetaTreeNode): string | undefined {
43
- const paths = meta?.paths || [];
44
- if (paths.length === 0) return undefined;
45
- // No inner spaces — matches the v1 storage shape exactly so round-trips
46
- // through the API stay byte-stable.
47
- return `{{${paths.join('.')}}}`;
47
+ /**
48
+ * Factory: returns a `parseValueToPath` bound to the given delimiters.
49
+ * Anchored (`^…$`) only treats the whole input as a single variable
50
+ * reference, matching the v1 single-line picker behaviour.
51
+ */
52
+ export function makeParseVariablePath(delimiters: VariableDelimiters = DEFAULT_DELIMITERS) {
53
+ const [open, close] = delimiters;
54
+ const re = new RegExp(`^${escapeForRegExp(open)}\\s*(.+?)\\s*${escapeForRegExp(close)}$`);
55
+ return (value?: string): string[] | undefined => {
56
+ if (typeof value !== 'string') return undefined;
57
+ const match = value.trim().match(re);
58
+ if (!match) return undefined;
59
+ let pathString = match[1];
60
+ // Backwards-compat: accept the legacy `ctx.` prefix so values produced by
61
+ // pre-fix versions of the picker still resolve to a labelled pill.
62
+ if (pathString === 'ctx') return [];
63
+ if (pathString.startsWith('ctx.')) pathString = pathString.slice(4);
64
+ return pathString.split('.');
65
+ };
48
66
  }
49
67
 
68
+ /**
69
+ * Factory: returns a `formatPathToValue` bound to the given delimiters.
70
+ * No inner spaces — matches the v1 storage shape exactly so round-trips
71
+ * through the API stay byte-stable.
72
+ */
73
+ export function makeFormatVariablePath(delimiters: VariableDelimiters = DEFAULT_DELIMITERS) {
74
+ const [open, close] = delimiters;
75
+ return (meta?: MetaTreeNode): string | undefined => {
76
+ const paths = meta?.paths || [];
77
+ if (paths.length === 0) return undefined;
78
+ return `${open}${paths.join('.')}${close}`;
79
+ };
80
+ }
81
+
82
+ /**
83
+ * Factory: returns a global regex matching every occurrence of the
84
+ * variable token within a longer string. Used by `VariableHybridInput`
85
+ * to render embedded variables as pills.
86
+ */
87
+ export function makeVariableRegExp(delimiters: VariableDelimiters = DEFAULT_DELIMITERS): RegExp {
88
+ const [open, close] = delimiters;
89
+ return new RegExp(`${escapeForRegExp(open)}\\s*([^{}]+?)\\s*${escapeForRegExp(close)}`, 'g');
90
+ }
91
+
92
+ // Default exports — `{{ ... }}` for the most common case. Kept named so
93
+ // existing callers don't need to switch to the factory.
94
+ export const parseVariablePath = makeParseVariablePath();
95
+ export const formatVariablePath = makeFormatVariablePath();
96
+
50
97
  const META_TREE_CACHE_PREFIX = '@nocobase/client-v2:VariableInput:metaTree';
51
98
 
52
99
  /**
@@ -123,8 +170,22 @@ export interface VariableInputProps {
123
170
  * Override the converters used by the underlying `VariableHybridInput`.
124
171
  * Mostly useful when the caller wants to constrain `formatPathToValue` to a
125
172
  * specific namespace (see `EnvVariableInput` for that pattern).
173
+ *
174
+ * Takes precedence over `delimiters` when both are set on the same field
175
+ * (an explicit converter wins over the delimiter-derived one).
126
176
  */
127
177
  converters?: VariableHybridInputConverters;
178
+ /**
179
+ * Token pair wrapping variable references in the stored string. Defaults
180
+ * to `['{{', '}}']` — the standard NocoBase server-template form,
181
+ * HTML-escaped by Handlebars. Pass `['{{{', '}}}']` for fields rendered
182
+ * as HTML where escaping would corrupt the variable value (e.g. the
183
+ * in-app message body).
184
+ *
185
+ * Ignored when `converters` is also supplied — caller-provided converters
186
+ * win.
187
+ */
188
+ delimiters?: VariableDelimiters;
128
189
  className?: string;
129
190
  style?: React.CSSProperties;
130
191
  }
@@ -136,16 +197,24 @@ export interface VariableInputProps {
136
197
  * line of mixed literal+variable content is appropriate.
137
198
  */
138
199
  export function VariableInput(props: VariableInputProps) {
139
- const { namespaces, extraNodes, converters, ...rest } = props;
200
+ const { namespaces, extraNodes, converters, delimiters, ...rest } = props;
140
201
  const metaTree = useFilteredMetaTree({ namespaces, extraNodes });
141
- const mergedConverters = useMemo<VariableHybridInputConverters>(
142
- () => ({
143
- formatPathToValue: formatVariablePath,
144
- parseValueToPath: parseVariablePath,
202
+ const mergedConverters = useMemo<VariableHybridInputConverters>(() => {
203
+ // Default delimiters → reuse the pre-built singletons.
204
+ if (!delimiters) {
205
+ return {
206
+ formatPathToValue: formatVariablePath,
207
+ parseValueToPath: parseVariablePath,
208
+ ...converters,
209
+ };
210
+ }
211
+ return {
212
+ formatPathToValue: makeFormatVariablePath(delimiters),
213
+ parseValueToPath: makeParseVariablePath(delimiters),
214
+ variableRegExp: makeVariableRegExp(delimiters),
145
215
  ...converters,
146
- }),
147
- [converters],
148
- );
216
+ };
217
+ }, [converters, delimiters]);
149
218
  return <VariableHybridInput {...rest} converters={mergedConverters} metaTree={metaTree} />;
150
219
  }
151
220
 
@@ -161,9 +230,13 @@ export interface VariableTextAreaProps extends Omit<VariableInputProps, 'convert
161
230
  * is desirable (the server expands them at render time).
162
231
  */
163
232
  export function VariableTextArea(props: VariableTextAreaProps) {
164
- const { namespaces, extraNodes, rows, maxRows, style, ...rest } = props;
233
+ const { namespaces, extraNodes, rows, maxRows, style, delimiters, ...rest } = props;
165
234
  const metaTree = useFilteredMetaTree({ namespaces, extraNodes });
166
235
  const metaTreeGetter = useMemo(() => () => metaTree, [metaTree]);
236
+ const formatPathToValue = useMemo(
237
+ () => (delimiters ? makeFormatVariablePath(delimiters) : formatVariablePath),
238
+ [delimiters],
239
+ );
167
240
  return (
168
241
  <TextAreaWithContextSelector
169
242
  {...rest}
@@ -171,7 +244,7 @@ export function VariableTextArea(props: VariableTextAreaProps) {
171
244
  maxRows={maxRows}
172
245
  style={style}
173
246
  metaTree={metaTreeGetter}
174
- formatPathToValue={(meta) => formatVariablePath(meta) ?? ''}
247
+ formatPathToValue={(meta) => formatPathToValue(meta) ?? ''}
175
248
  />
176
249
  );
177
250
  }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { describe, expect, it } from 'vitest';
11
+ import {
12
+ formatVariablePath,
13
+ makeFormatVariablePath,
14
+ makeParseVariablePath,
15
+ makeVariableRegExp,
16
+ parseVariablePath,
17
+ } from '../VariableInput';
18
+
19
+ describe('VariableInput delimiter helpers', () => {
20
+ describe('default delimiters {{ }}', () => {
21
+ it('formats meta nodes into `{{x.y}}` with no inner spaces', () => {
22
+ expect(formatVariablePath({ paths: ['$user', 'id'] } as any)).toBe('{{$user.id}}');
23
+ });
24
+
25
+ it('parses `{{x.y}}` into a path array', () => {
26
+ expect(parseVariablePath('{{ $user.id }}')).toEqual(['$user', 'id']);
27
+ expect(parseVariablePath('{{$user.id}}')).toEqual(['$user', 'id']);
28
+ });
29
+
30
+ it('strips a legacy `ctx.` prefix for backwards-compat', () => {
31
+ expect(parseVariablePath('{{ctx.$user.id}}')).toEqual(['$user', 'id']);
32
+ expect(parseVariablePath('{{ctx}}')).toEqual([]);
33
+ });
34
+
35
+ it('returns undefined for plain text', () => {
36
+ expect(parseVariablePath('hello world')).toBeUndefined();
37
+ expect(parseVariablePath('')).toBeUndefined();
38
+ expect(parseVariablePath(undefined)).toBeUndefined();
39
+ });
40
+ });
41
+
42
+ describe('triple-brace delimiters {{{ }}}', () => {
43
+ const format = makeFormatVariablePath(['{{{', '}}}']);
44
+ const parse = makeParseVariablePath(['{{{', '}}}']);
45
+
46
+ it('formats meta nodes into `{{{x.y}}}`', () => {
47
+ expect(format({ paths: ['$user', 'id'] } as any)).toBe('{{{$user.id}}}');
48
+ });
49
+
50
+ it('parses `{{{x.y}}}` into a path array', () => {
51
+ expect(parse('{{{$user.id}}}')).toEqual(['$user', 'id']);
52
+ expect(parse('{{{ $user.id }}}')).toEqual(['$user', 'id']);
53
+ });
54
+
55
+ it('does not match the double-brace form', () => {
56
+ expect(parse('{{$user.id}}')).toBeUndefined();
57
+ });
58
+ });
59
+
60
+ describe('makeVariableRegExp', () => {
61
+ it('matches every occurrence in a longer string under default delimiters', () => {
62
+ const re = makeVariableRegExp();
63
+ const matches = Array.from('hello {{ $user.id }} world {{ $env.X }}'.matchAll(re)).map((m) => m[1]);
64
+ expect(matches).toEqual(['$user.id', '$env.X']);
65
+ });
66
+
67
+ it('matches triple-brace occurrences when configured', () => {
68
+ const re = makeVariableRegExp(['{{{', '}}}']);
69
+ const matches = Array.from('hi {{{$user.id}}} :)'.matchAll(re)).map((m) => m[1]);
70
+ expect(matches).toEqual(['$user.id']);
71
+ });
72
+
73
+ it('does not match double-brace occurrences under triple-brace config', () => {
74
+ const re = makeVariableRegExp(['{{{', '}}}']);
75
+ const matches = Array.from('plain {{ x }} text'.matchAll(re));
76
+ expect(matches).toHaveLength(0);
77
+ });
78
+ });
79
+
80
+ it('handles empty paths consistently', () => {
81
+ expect(formatVariablePath({ paths: [] } as any)).toBeUndefined();
82
+ expect(formatVariablePath(undefined)).toBeUndefined();
83
+ expect(makeFormatVariablePath(['{{{', '}}}'])({ paths: [] } as any)).toBeUndefined();
84
+ });
85
+ });
@@ -0,0 +1,111 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { FilterOutlined } from '@ant-design/icons';
11
+ import type { Collection } from '@nocobase/flow-engine';
12
+ import { Button, type ButtonProps, Popover, type PopoverProps } from 'antd';
13
+ import React, { FC, useState } from 'react';
14
+ import { FilterContent } from '../../../flow/components/filter';
15
+ import { CompiledFilter, FilterApplyAction, useFilterActionProps } from './useFilterActionProps';
16
+
17
+ const identity = (s: string) => s;
18
+
19
+ export interface CollectionFilterProps {
20
+ /** Collection whose fields drive the filter row's field picker. */
21
+ collection: Collection | undefined;
22
+ /** Called on Submit or Reset with the compiled NocoBase filter param (`undefined` when cleared). */
23
+ onChange: (filter: CompiledFilter) => void;
24
+ /** Translator. Defaults to identity. */
25
+ t?: (key: string, options?: Record<string, any>) => string;
26
+ /** Whitelist of root-level field names to expose. */
27
+ filterableFieldNames?: string[];
28
+ /**
29
+ * Blacklist of root-level field names to drop. Mirrors v1's `nonfilterable: [...]` on `Filter.Action`. When both `filterableFieldNames` and this prop are supplied, both apply (final = whitelist ∩ ¬blacklist).
30
+ */
31
+ nonfilterableFieldNames?: string[];
32
+ /**
33
+ * Bypass the `filterableFieldNames` whitelist.
34
+ *
35
+ * Legacy escape hatch — prefer adjusting `filterableFieldNames` / `nonfilterableFieldNames` instead.
36
+ */
37
+ noIgnore?: boolean;
38
+ /** Override the trigger button's label. Defaults to `t('Filter')`, or the v1-style `t('{{count}} filter items', { count })` when conditions are present. */
39
+ buttonText?: React.ReactNode;
40
+ /** Swap the default `t('Filter')` label for v1's `t('{{count}} filter items', { count })` when conditions are present. Defaults to `true`. */
41
+ showCount?: boolean;
42
+ /** Pass-through props for the antd `<Popover>`. */
43
+ popoverProps?: Omit<PopoverProps, 'open' | 'onOpenChange' | 'content' | 'children'>;
44
+ /** Pass-through props for the trigger `<Button>`. */
45
+ buttonProps?: Omit<ButtonProps, 'icon' | 'type' | 'children' | 'onClick'>;
46
+ /** Min-width applied to the popover body. Defaults to `520`. */
47
+ popoverMinWidth?: number;
48
+ }
49
+
50
+ /**
51
+ * Filter button bound to a collection. Renders an antd `<Popover>` over a `<Button>`; the popover hosts a multi-condition filter form (field picker, operator, value). Submit dismisses the popover and emits the compiled filter via `onChange`; Reset keeps the popover open and emits `undefined`.
52
+ *
53
+ * Pair with `<ExtendCollectionsProvider>` when the target collection is client-only (e.g. a `schema-only` server collection that isn't auto-published to the v2 data source).
54
+ */
55
+ export const CollectionFilter: FC<CollectionFilterProps> = (props) => {
56
+ const {
57
+ collection,
58
+ onChange,
59
+ t = identity,
60
+ filterableFieldNames,
61
+ nonfilterableFieldNames,
62
+ noIgnore,
63
+ buttonText,
64
+ showCount = true,
65
+ popoverProps,
66
+ buttonProps,
67
+ popoverMinWidth = 520,
68
+ } = props;
69
+
70
+ const [open, setOpen] = useState(false);
71
+
72
+ const filterAction = useFilterActionProps({
73
+ collection,
74
+ filterableFieldNames,
75
+ nonfilterableFieldNames,
76
+ noIgnore,
77
+ t,
78
+ onApply: (filter: CompiledFilter, action: FilterApplyAction) => {
79
+ onChange(filter);
80
+ if (action === 'submit') setOpen(false);
81
+ },
82
+ });
83
+
84
+ // Matches v1's `Filter.Action`: when at least one condition is set, the button label switches to the count-aware string (`"N 个筛选项"` in zh-CN). The button itself stays in the default (white) style — v1 never flipped it to `type='primary'`.
85
+ const label =
86
+ buttonText ??
87
+ (showCount && filterAction.conditionCount > 0
88
+ ? t('{{count}} filter items', { count: filterAction.conditionCount })
89
+ : t('Filter'));
90
+
91
+ return (
92
+ <Popover
93
+ trigger="click"
94
+ placement="bottomLeft"
95
+ {...popoverProps}
96
+ open={open}
97
+ onOpenChange={setOpen}
98
+ content={
99
+ <div style={{ minWidth: popoverMinWidth }}>
100
+ <FilterContent value={filterAction.value} ctx={filterAction.ctx} FilterItem={filterAction.FilterItem} />
101
+ </div>
102
+ }
103
+ >
104
+ <Button icon={<FilterOutlined />} disabled={!collection} {...buttonProps}>
105
+ {label}
106
+ </Button>
107
+ </Popover>
108
+ );
109
+ };
110
+
111
+ export default CollectionFilter;
@@ -0,0 +1,184 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { css } from '@emotion/css';
11
+ import { Collection, observer } from '@nocobase/flow-engine';
12
+ import { Cascader, Select, Space } from 'antd';
13
+ import React, { FC, useMemo } from 'react';
14
+ import { FilterOption, useFilterOptions } from '../../../flow/components/filter/useFilterOptions';
15
+ import { FilterValueInput } from './FilterValueInput';
16
+
17
+ /**
18
+ * Lift the Cascader sub-menu height so a target collection with many fields (e.g. `users` → id / nickname / username / email / phone / password / createdAt / updatedAt / roles / createdBy / updatedBy) doesn't get truncated below the default antd menu viewport.
19
+ */
20
+ const cascaderPopupClass = css`
21
+ .ant-cascader-menu {
22
+ height: fit-content;
23
+ max-height: 50vh;
24
+ }
25
+ `;
26
+
27
+ export interface CollectionFilterItemValue {
28
+ path: string;
29
+ operator: string;
30
+ /** Operator-dependent — string for default ops, descriptor for $date*, etc. */
31
+ value: any;
32
+ }
33
+
34
+ type CascaderOption = {
35
+ value: string;
36
+ label: string;
37
+ children?: CascaderOption[];
38
+ };
39
+
40
+ export interface CollectionFilterItemProps {
41
+ /** Reactive filter row managed by the parent `FilterContainer`. */
42
+ value: CollectionFilterItemValue;
43
+ /** Target collection whose fields populate the field selector. */
44
+ collection: Collection;
45
+ /** Whitelist of field names to expose; empty/undefined means all filterable fields. */
46
+ filterableFieldNames?: string[];
47
+ /**
48
+ * Blacklist of field names to drop. Mirrors v1's `nonfilterable: [...]` on `Filter.Action`. When both whitelist and blacklist are supplied, both apply (final = whitelist ∩ ¬blacklist).
49
+ */
50
+ nonfilterableFieldNames?: string[];
51
+ /**
52
+ * Bypass the `filterableFieldNames` whitelist (matches the legacy FilterItem `noIgnore`).
53
+ *
54
+ * Legacy escape hatch — prefer adjusting `filterableFieldNames` / `nonfilterableFieldNames` instead.
55
+ */
56
+ noIgnore?: boolean;
57
+ /** Translator; defaults to identity so callers can omit it. */
58
+ t?: (key: string) => string;
59
+ }
60
+
61
+ const identity = (s: string) => s;
62
+
63
+ /**
64
+ * Walk a tree of field options by name path, returning the leaf option (or undefined when the path doesn't resolve). Used to look up operators for the currently selected field.
65
+ */
66
+ const findOptionByPath = (options: FilterOption[], path: string[]): FilterOption | undefined => {
67
+ if (!path.length) return undefined;
68
+ const [head, ...rest] = path;
69
+ const match = options.find((option) => option.name === head);
70
+ if (!match) return undefined;
71
+ if (!rest.length) return match;
72
+ return findOptionByPath(match.children || [], rest);
73
+ };
74
+
75
+ /**
76
+ * Convert the field-option tree (as produced by `useFilterOptions`) into antd `Cascader`'s expected `{ value, label, children }` shape. With `changeOnSelect={false}` (see the render below), antd already requires selection at a leaf — we don't need to mark association parents as `disabled`, and doing so would also block `expandTrigger="hover"` from descending into them.
77
+ */
78
+ const toCascaderOptions = (options: FilterOption[]): CascaderOption[] =>
79
+ options.map((option) => {
80
+ const children = option.children?.length ? toCascaderOptions(option.children) : undefined;
81
+ return {
82
+ value: option.name,
83
+ label: option.title,
84
+ children,
85
+ };
86
+ });
87
+
88
+ /**
89
+ * Filter row bound directly to a `Collection`, with no `FlowModel` dependency. Use this from settings pages or other surfaces that need a filter UI but don't have (and shouldn't synthesise) a block model just to satisfy `FilterItem`. Pair with `FilterContainer` via either an inline wrapper or `createCollectionFilterItem(collection)`.
90
+ *
91
+ * The field selector is an antd `Cascader`, mirroring v1's `Filter.Action` so association fields (belongsTo / m2o / etc.) can be drilled into — picking `user.username` is a first-class action. The value renderer is delegated to `FilterValueInput`, which dispatches to interface-specific controls (the smart date picker for `$date*` operators, tag-mode Select for array/enum, etc.) the same way v1's `DynamicComponent` did.
92
+ */
93
+ export const CollectionFilterItem: FC<CollectionFilterItemProps> = observer(
94
+ (props) => {
95
+ const { collection, filterableFieldNames, nonfilterableFieldNames, noIgnore = false, t = identity } = props;
96
+ const { path: leftValue, operator, value: rightValue } = props.value;
97
+
98
+ const options = useFilterOptions(collection, { filterableFieldNames, nonfilterableFieldNames, noIgnore, t });
99
+
100
+ const cascaderOptions = useMemo(() => toCascaderOptions(options), [options]);
101
+
102
+ const fieldPath = useMemo(() => (leftValue ? leftValue.split('.') : []), [leftValue]);
103
+
104
+ const selectedField = useMemo(() => findOptionByPath(options, fieldPath), [options, fieldPath]);
105
+
106
+ const operatorOptions = useMemo(() => selectedField?.operators || [], [selectedField]);
107
+
108
+ const selectedOperator = useMemo(
109
+ () => operatorOptions.find((op) => op.value === operator),
110
+ [operatorOptions, operator],
111
+ );
112
+
113
+ const handleFieldChange = (next: (string | number)[]) => {
114
+ const path = next.map(String);
115
+ props.value.path = path.join('.');
116
+ const leaf = findOptionByPath(options, path);
117
+ props.value.operator = leaf?.operators?.[0]?.value || '';
118
+ // The value's shape is operator-dependent (e.g. string for `$eq`, `{ type, number, unit }` for `$dateInPast`); reset on every field change so stale shapes don't leak across interfaces.
119
+ props.value.value = undefined;
120
+ };
121
+ const handleOperatorChange = (next: string) => {
122
+ props.value.operator = next;
123
+ // Same rationale as above — switching from `$eq` (string) to `$dateOn` (date descriptor) makes the previous value structurally incompatible. v1 handled this by remounting the DynamicComponent on operator change; we explicitly clear.
124
+ props.value.value = undefined;
125
+ };
126
+ const handleValueChange = (next: any) => {
127
+ props.value.value = next;
128
+ };
129
+
130
+ // Widths mirror the long-standing `FilterItem` row (200 / 120) so a settings page mixing CollectionFilterItem and FilterContainer doesn't visually drift from existing block-bound filter rows.
131
+ return (
132
+ <Space wrap>
133
+ <Cascader
134
+ style={{ width: 200 }}
135
+ placeholder={t('Select field')}
136
+ options={cascaderOptions}
137
+ value={fieldPath}
138
+ onChange={handleFieldChange}
139
+ changeOnSelect={false}
140
+ expandTrigger="click"
141
+ popupClassName={cascaderPopupClass}
142
+ />
143
+ <Select
144
+ style={{ width: 120 }}
145
+ placeholder={t('Comparision')}
146
+ value={operator || undefined}
147
+ onChange={handleOperatorChange}
148
+ disabled={!leftValue || operatorOptions.length === 0}
149
+ >
150
+ {operatorOptions.map((op) => (
151
+ <Select.Option key={op.value} value={op.value}>
152
+ {op.label}
153
+ </Select.Option>
154
+ ))}
155
+ </Select>
156
+ <FilterValueInput
157
+ field={selectedField}
158
+ operator={selectedOperator}
159
+ value={rightValue}
160
+ onChange={handleValueChange}
161
+ placeholder={t('Enter value')}
162
+ t={t}
163
+ />
164
+ </Space>
165
+ );
166
+ },
167
+ { displayName: 'CollectionFilterItem' },
168
+ );
169
+
170
+ /**
171
+ * Convenience factory returning a `FilterContainer`-compatible `FilterItem` component bound to a specific collection. Avoids creating an inline closure on every parent render, which would otherwise reset any focused inner antd control.
172
+ */
173
+ export function createCollectionFilterItem(
174
+ collection: Collection,
175
+ bound?: Pick<CollectionFilterItemProps, 'filterableFieldNames' | 'nonfilterableFieldNames' | 'noIgnore' | 't'>,
176
+ ) {
177
+ const Component: FC<{ value: CollectionFilterItemValue }> = (props) => (
178
+ <CollectionFilterItem {...bound} value={props.value} collection={collection} />
179
+ );
180
+ Component.displayName = 'BoundCollectionFilterItem';
181
+ return Component;
182
+ }
183
+
184
+ export default CollectionFilterItem;