@nocobase/client-v2 2.2.0-beta.8 → 2.2.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 (271) hide show
  1. package/es/APIClient.d.ts +13 -3
  2. package/es/BaseApplication.d.ts +3 -0
  3. package/es/RouteRepository.d.ts +8 -0
  4. package/es/RouterManager.d.ts +15 -0
  5. package/es/authRedirect.d.ts +1 -0
  6. package/es/collection-field-interface/CollectionFieldInterface.d.ts +1 -0
  7. package/es/collection-field-interface/CollectionFieldInterfaceManager.d.ts +1 -0
  8. package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
  9. package/es/components/category-tabs/index.d.ts +9 -0
  10. package/es/components/form/ScanInput/useCodeScanner.d.ts +3 -2
  11. package/es/components/form/TypedVariableInput.d.ts +31 -5
  12. package/es/components/form/filter/CollectionFilter.d.ts +2 -0
  13. package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
  14. package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
  15. package/es/components/form/filter/index.d.ts +2 -0
  16. package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
  17. package/es/components/index.d.ts +1 -0
  18. package/es/entry-actions/EntryActionManager.d.ts +24 -0
  19. package/es/entry-actions/index.d.ts +9 -0
  20. package/es/flow/actions/index.d.ts +1 -1
  21. package/es/flow/actions/linkageRules.d.ts +27 -0
  22. package/es/flow/admin-shell/BaseLayoutModel.d.ts +6 -0
  23. package/es/flow/admin-shell/BaseLayoutRouteCoordinator.d.ts +7 -0
  24. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -0
  25. package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
  26. package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
  27. package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
  28. package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
  29. package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
  30. package/es/flow/components/FieldAssignValueInput.d.ts +7 -24
  31. package/es/flow/components/FlowRoute.d.ts +2 -2
  32. package/es/flow/components/RunJSValueEditor.d.ts +1 -0
  33. package/es/flow/components/field-value-variable/DateVariableEditor.d.ts +24 -0
  34. package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +31 -0
  35. package/es/flow/components/field-value-variable/dateValue.d.ts +36 -0
  36. package/es/flow/components/field-value-variable/index.d.ts +11 -0
  37. package/es/flow/components/filter/FilterGroup.d.ts +1 -0
  38. package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
  39. package/es/flow/components/placeholders/BlockPlaceholder.d.ts +1 -0
  40. package/es/flow/index.d.ts +1 -0
  41. package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -0
  42. package/es/flow/internal/utils/operatorSchemaHelper.d.ts +2 -2
  43. package/es/flow/models/actions/UpdateRecordActionUtils.d.ts +8 -2
  44. package/es/flow/models/base/ActionModelCore.d.ts +6 -2
  45. package/es/flow/models/base/BlockGridModel.d.ts +3 -0
  46. package/es/flow/models/base/CollectionBlockModel.d.ts +3 -0
  47. package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
  48. package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
  49. package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
  50. package/es/flow/models/blocks/details/DetailsBlockModel.d.ts +3 -0
  51. package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +1 -0
  52. package/es/flow/models/blocks/filter-form/FilterFormSubmitActionModel.d.ts +3 -1
  53. package/es/flow/models/blocks/form/FormBlockModel.d.ts +7 -0
  54. package/es/flow/models/blocks/form/FormGridModel.d.ts +6 -0
  55. package/es/flow/models/blocks/form/QuickEditFormModel.d.ts +17 -2
  56. package/es/flow/models/blocks/form/value-runtime/rules.d.ts +1 -0
  57. package/es/flow/models/blocks/table/JSColumnModel.d.ts +2 -0
  58. package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
  59. package/es/flow/models/blocks/table/TableColumnModel.d.ts +12 -0
  60. package/es/flow/models/blocks/table/utils.d.ts +1 -0
  61. package/es/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.d.ts +2 -1
  62. package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +0 -17
  63. package/es/flow/models/fields/AssociationFieldModel/recordSelectShared.d.ts +41 -0
  64. package/es/flow/models/fields/DateTimeFieldModel/dateLimit.d.ts +15 -7
  65. package/es/flow/routeTransientInputArgs.d.ts +14 -0
  66. package/es/flow-compat/fieldValidationConstants.d.ts +1 -1
  67. package/es/flow-compat/passwordUtils.d.ts +1 -1
  68. package/es/flow-compat/routeTypes.d.ts +1 -0
  69. package/es/index.d.ts +7 -0
  70. package/es/index.mjs +301 -177
  71. package/es/ui-operation/index.d.ts +15 -0
  72. package/es/ui-operation/ui-operation-codec.d.ts +10 -0
  73. package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
  74. package/es/utils/index.d.ts +1 -0
  75. package/es/utils/markdownSanitize.d.ts +11 -0
  76. package/lib/index.js +313 -189
  77. package/lib/locale/languageCodes.js +3 -1
  78. package/package.json +9 -7
  79. package/src/APIClient.ts +90 -7
  80. package/src/Application.tsx +7 -1
  81. package/src/BaseApplication.tsx +13 -6
  82. package/src/RouteRepository.ts +25 -0
  83. package/src/RouterManager.tsx +142 -1
  84. package/src/__tests__/APIClient.test.tsx +58 -0
  85. package/src/__tests__/RouteRepository.test.ts +23 -0
  86. package/src/__tests__/RouterManager.test.ts +125 -0
  87. package/src/__tests__/app.test.tsx +73 -0
  88. package/src/__tests__/authRedirect.test.ts +17 -0
  89. package/src/__tests__/browserChecker.test.ts +61 -0
  90. package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
  91. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +35 -2
  92. package/src/__tests__/settings-center.test.tsx +270 -6
  93. package/src/acl/ACLProvider.tsx +2 -0
  94. package/src/acl/__tests__/ACLProvider.test.tsx +92 -0
  95. package/src/authRedirect.ts +38 -0
  96. package/src/collection-field-interface/CollectionFieldInterface.ts +1 -0
  97. package/src/collection-field-interface/CollectionFieldInterfaceManager.ts +1 -0
  98. package/src/collection-manager/field-validation.ts +1 -1
  99. package/src/components/README.md +7 -1
  100. package/src/components/README.zh-CN.md +6 -1
  101. package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
  102. package/src/components/category-tabs/index.ts +10 -0
  103. package/src/components/form/JsonTextArea.tsx +4 -0
  104. package/src/components/form/ScanInput/CodeScanner.tsx +79 -35
  105. package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +101 -0
  106. package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +284 -11
  107. package/src/components/form/ScanInput/useCodeScanner.ts +332 -24
  108. package/src/components/form/TypedVariableInput.tsx +452 -101
  109. package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
  110. package/src/components/form/filter/CollectionFilter.tsx +4 -0
  111. package/src/components/form/filter/CollectionFilterItem.tsx +36 -9
  112. package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
  113. package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +55 -0
  114. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
  115. package/src/components/form/filter/index.ts +2 -0
  116. package/src/components/form/filter/useFilterActionProps.ts +37 -6
  117. package/src/components/form/table/Table.tsx +81 -6
  118. package/src/components/form/table/__tests__/Table.columnWidth.test.tsx +433 -0
  119. package/src/components/index.ts +1 -0
  120. package/src/entry-actions/EntryActionManager.ts +76 -0
  121. package/src/entry-actions/index.ts +10 -0
  122. package/src/flow/FlowPage.tsx +38 -3
  123. package/src/flow/__tests__/FlowPage.test.tsx +201 -27
  124. package/src/flow/__tests__/FlowRoute.test.tsx +675 -12
  125. package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
  126. package/src/flow/actions/__tests__/actionLinkageRules.forkProps.test.ts +314 -0
  127. package/src/flow/actions/__tests__/dataScopeFilter.test.ts +62 -0
  128. package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +102 -0
  129. package/src/flow/actions/__tests__/linkageRules.actionStates.test.ts +33 -0
  130. package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +72 -0
  131. package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
  132. package/src/flow/actions/__tests__/linkageRulesRefresh.test.ts +7 -3
  133. package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +80 -20
  134. package/src/flow/actions/dataScopeFilter.ts +10 -1
  135. package/src/flow/actions/dateTimeFormat.tsx +2 -2
  136. package/src/flow/actions/index.ts +2 -0
  137. package/src/flow/actions/linkageRules.tsx +144 -26
  138. package/src/flow/actions/linkageRulesRefresh.tsx +2 -6
  139. package/src/flow/actions/openView.tsx +21 -1
  140. package/src/flow/admin-shell/BaseLayoutModel.tsx +124 -0
  141. package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +184 -42
  142. package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +1016 -119
  143. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +41 -5
  144. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +177 -1
  145. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +20 -0
  146. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +78 -59
  147. package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
  148. package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
  149. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +253 -6
  150. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +228 -0
  151. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +436 -2
  152. package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +48 -0
  153. package/src/flow/admin-shell/admin-layout/index.ts +1 -0
  154. package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
  155. package/src/flow/common/Markdown/Display.tsx +14 -3
  156. package/src/flow/common/Markdown/Edit.tsx +19 -7
  157. package/src/flow/common/Markdown/style.ts +4 -0
  158. package/src/flow/components/BlockItemCard.tsx +2 -2
  159. package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
  160. package/src/flow/components/FieldAssignValueInput.tsx +72 -584
  161. package/src/flow/components/FlowRoute.tsx +204 -46
  162. package/src/flow/components/RunJSValueEditor.tsx +9 -1
  163. package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +216 -0
  164. package/src/flow/components/field-value-variable/DateVariableEditor.tsx +181 -0
  165. package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +326 -0
  166. package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +380 -0
  167. package/src/flow/components/field-value-variable/dateValue.ts +223 -0
  168. package/src/flow/components/field-value-variable/index.ts +12 -0
  169. package/src/flow/components/filter/FilterGroup.tsx +33 -5
  170. package/src/flow/components/filter/VariableFilterItem.tsx +170 -13
  171. package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
  172. package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
  173. package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +195 -1
  174. package/src/flow/components/placeholders/BlockPlaceholder.tsx +70 -23
  175. package/src/flow/components/placeholders/__tests__/BlockPlaceholder.test.tsx +57 -7
  176. package/src/flow/index.ts +3 -0
  177. package/src/flow/internal/components/Markdown/util.ts +2 -1
  178. package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
  179. package/src/flow/internal/utils/operatorSchemaHelper.ts +3 -2
  180. package/src/flow/models/actions/UpdateRecordActionModel.tsx +18 -1
  181. package/src/flow/models/actions/UpdateRecordActionUtils.ts +18 -6
  182. package/src/flow/models/actions/__tests__/UpdateRecordActionModel.test.ts +76 -4
  183. package/src/flow/models/base/ActionModel.tsx +10 -8
  184. package/src/flow/models/base/ActionModelCore.tsx +16 -2
  185. package/src/flow/models/base/BlockGridModel.tsx +26 -0
  186. package/src/flow/models/base/CollectionBlockModel.tsx +38 -3
  187. package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
  188. package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
  189. package/src/flow/models/base/PageModel/PageTabModel.tsx +249 -18
  190. package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -10
  191. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
  192. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
  193. package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +1075 -7
  194. package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +49 -0
  195. package/src/flow/models/base/__tests__/BlockGridModel.selectSceneActivation.test.ts +124 -0
  196. package/src/flow/models/base/__tests__/CollectionBlockModel.addAppends.test.ts +41 -0
  197. package/src/flow/models/base/__tests__/CollectionBlockModel.initialBeforeRenderRefresh.test.ts +125 -9
  198. package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +28 -53
  199. package/src/flow/models/blocks/details/DetailsBlockModel.tsx +8 -3
  200. package/src/flow/models/blocks/details/__tests__/DetailsBlockModel.initialPaginationChangeRefresh.test.ts +32 -1
  201. package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +28 -3
  202. package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +36 -5
  203. package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +155 -25
  204. package/src/flow/models/blocks/filter-form/FilterFormSubmitActionModel.tsx +57 -4
  205. package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.onModelCreated.test.ts +174 -1
  206. package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.defineChildren.test.ts +395 -1
  207. package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.getFilterValue.test.ts +72 -0
  208. package/src/flow/models/blocks/filter-form/__tests__/FilterFormSubmitActionModel.lifecycle.test.ts +90 -0
  209. package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +66 -4
  210. package/src/flow/models/blocks/filter-manager/FilterManager.ts +5 -0
  211. package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.test.ts +40 -0
  212. package/src/flow/models/blocks/form/FormBlockModel.tsx +47 -0
  213. package/src/flow/models/blocks/form/FormGridModel.tsx +4 -0
  214. package/src/flow/models/blocks/form/QuickEditFormModel.tsx +189 -36
  215. package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +8 -2
  216. package/src/flow/models/blocks/form/__tests__/QuickEditFormModel.quickEdit.test.ts +350 -2
  217. package/src/flow/models/blocks/form/__tests__/runJsFormSubmit.test.ts +131 -0
  218. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +435 -0
  219. package/src/flow/models/blocks/form/value-runtime/rules.ts +67 -14
  220. package/src/flow/models/blocks/form/value-runtime/runtime.ts +43 -19
  221. package/src/flow/models/blocks/js-block/JSBlock.tsx +1 -1
  222. package/src/flow/models/blocks/table/JSColumnModel.tsx +10 -1
  223. package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +2 -1
  224. package/src/flow/models/blocks/table/TableBlockModel.tsx +29 -3
  225. package/src/flow/models/blocks/table/TableColumnModel.tsx +54 -11
  226. package/src/flow/models/blocks/table/__tests__/JSColumnModel.test.tsx +52 -5
  227. package/src/flow/models/blocks/table/__tests__/TableBlockModel.filterReset.test.ts +78 -0
  228. package/src/flow/models/blocks/table/__tests__/TableBlockModel.quickEditRefresh.test.ts +12 -0
  229. package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +84 -0
  230. package/src/flow/models/blocks/table/utils.ts +7 -0
  231. package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +33 -1
  232. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +10 -1
  233. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/__tests__/popupContext.test.ts +120 -0
  234. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.tsx +10 -2
  235. package/src/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.tsx +24 -1
  236. package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +54 -149
  237. package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +167 -3
  238. package/src/flow/models/fields/AssociationFieldModel/recordSelectShared.tsx +156 -0
  239. package/src/flow/models/fields/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +149 -0
  240. package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +149 -113
  241. package/src/flow/models/fields/DisplayNumberFieldModel.tsx +1 -1
  242. package/src/flow/models/fields/JsonFieldModel.tsx +31 -8
  243. package/src/flow/models/fields/NumberFieldModel.tsx +1 -1
  244. package/src/flow/models/fields/TextareaFieldModel.tsx +42 -19
  245. package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
  246. package/src/flow/models/fields/__tests__/DisplayNumberFieldModel.test.ts +33 -0
  247. package/src/flow/models/fields/__tests__/JsonFieldModel.test.ts +82 -0
  248. package/src/flow/models/fields/__tests__/NumberFieldModel.test.tsx +47 -0
  249. package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +32 -1
  250. package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
  251. package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +26 -10
  252. package/src/flow/models/fields/mobile-components/MobileSelect.tsx +51 -14
  253. package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +139 -13
  254. package/src/flow/models/topbar/TopbarActionModel.tsx +78 -3
  255. package/src/flow/routeTransientInputArgs.ts +27 -0
  256. package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
  257. package/src/flow/utils/dataScopeFormValueClear.ts +4 -3
  258. package/src/flow-compat/fieldValidationConstants.ts +1 -1
  259. package/src/flow-compat/routeTypes.ts +1 -0
  260. package/src/index.ts +7 -0
  261. package/src/layout-manager/LayoutContentRoute.tsx +2 -1
  262. package/src/layout-manager/LayoutRoute.tsx +2 -1
  263. package/src/layout-manager/__tests__/LayoutRoute.test.tsx +87 -1
  264. package/src/locale/languageCodes.ts +3 -1
  265. package/src/nocobase-buildin-plugin/index.tsx +19 -1
  266. package/src/settings-center/AdminSettingsLayout.tsx +23 -2
  267. package/src/ui-operation/index.ts +33 -0
  268. package/src/ui-operation/ui-operation-codec.ts +54 -0
  269. package/src/utils/getRouteRuntimeVersion.ts +185 -0
  270. package/src/utils/index.tsx +1 -0
  271. package/src/utils/markdownSanitize.ts +88 -0
@@ -18,6 +18,7 @@ import { Link, useLocation } from 'react-router-dom';
18
18
  import { useACLRoleContext } from '../../../acl';
19
19
  import type { BaseApplication } from '../../../BaseApplication';
20
20
  import type { PluginSettingsPageType } from '../../../PluginSettingsManager';
21
+ import { shouldOpenAdminRouteInNewWindow } from '../../../RouterManager';
21
22
  import { useApp } from '../../../hooks/useApp';
22
23
  import {
23
24
  filterRenderableSettings,
@@ -65,7 +66,10 @@ const topbarActionTriggerClassName = css`
65
66
  height: 100%;
66
67
  `;
67
68
 
68
- type TopbarSettingsAppLike = Pick<BaseApplication<any>, 'router' | 'getPublicPath'>;
69
+ type TopbarSettingsAppLike = Pick<
70
+ BaseApplication<any>,
71
+ 'name' | 'router' | 'getPublicPath' | 'getHref' | 'layoutManager'
72
+ >;
69
73
 
70
74
  const normalizeTopbarPath = (pathname?: string) => {
71
75
  const trimmed = pathname?.trim();
@@ -103,10 +107,57 @@ const stripTopbarRouterBasePath = (pathname: string, basename?: string) => {
103
107
  return normalizedPath;
104
108
  };
105
109
 
110
+ const getTopbarAppPath = (pathname: string) => {
111
+ const normalizedPath = normalizeTopbarPath(pathname);
112
+ const match = /^(.*?\/(?:apps|_app)\/[^/]+)(?=\/|$)/.exec(normalizedPath);
113
+ const appPath = match?.[1] || '';
114
+
115
+ return {
116
+ appPath,
117
+ routePath: appPath ? normalizeTopbarPath(normalizedPath.slice(appPath.length)) : normalizedPath,
118
+ };
119
+ };
120
+
121
+ const getTopbarContextAppPath = (app: TopbarSettingsAppLike | undefined, basename?: string) => {
122
+ const basenameAppPath = getTopbarAppPath(basename || '').appPath;
123
+ if (basenameAppPath) {
124
+ return basenameAppPath;
125
+ }
126
+
127
+ const publicPathAppPath = getTopbarAppPath(app?.getPublicPath?.() || '').appPath;
128
+ if (publicPathAppPath) {
129
+ return publicPathAppPath;
130
+ }
131
+
132
+ if (app?.name && app.name !== 'main' && app.getHref) {
133
+ return normalizeTopbarBasePath(app.getHref('/'));
134
+ }
135
+
136
+ return '';
137
+ };
138
+
139
+ const prependTopbarAppPath = (pathname: string, appPath: string) => {
140
+ const normalizedPath = normalizeTopbarPath(pathname);
141
+
142
+ if (!appPath || normalizedPath === appPath || normalizedPath.startsWith(`${appPath}/`)) {
143
+ return normalizedPath;
144
+ }
145
+
146
+ return `${appPath}${normalizedPath}`;
147
+ };
148
+
106
149
  const isAdminRuntimePath = (pathname: string) => {
107
150
  return pathname === '/admin' || pathname.startsWith('/admin/');
108
151
  };
109
152
 
153
+ const getTopbarAdminRoutePath = (app: TopbarSettingsAppLike | undefined) => {
154
+ try {
155
+ return app?.layoutManager?.getLayout?.('admin')?.routePath;
156
+ } catch {
157
+ return undefined;
158
+ }
159
+ };
160
+
110
161
  const buildTopbarDocumentHref = (targetPath: string, basename?: string) => {
111
162
  const normalizedTarget = normalizeTopbarPath(targetPath);
112
163
  const normalizedBase = normalizeTopbarBasePath(basename);
@@ -136,9 +187,33 @@ function TopbarInternalSettingsLabel(props: { title: React.ReactNode; path?: str
136
187
  const targetPath = props.path || '/admin/settings';
137
188
  const basename = getTopbarRouterBasePath(app);
138
189
  const currentPath = stripTopbarRouterBasePath(location.pathname, basename);
190
+ const currentLocationAppPath = getTopbarAppPath(currentPath);
191
+ const currentAppPath = currentLocationAppPath.appPath || getTopbarContextAppPath(app, basename);
192
+ const currentRoutePath = currentLocationAppPath.appPath ? currentLocationAppPath.routePath : currentPath;
193
+ const targetPathInCurrentApp = prependTopbarAppPath(stripTopbarRouterBasePath(targetPath, basename), currentAppPath);
194
+
195
+ if (currentAppPath) {
196
+ const href = buildTopbarDocumentHref(targetPathInCurrentApp, basename);
197
+ const shouldOpenInNewWindow = shouldOpenAdminRouteInNewWindow({
198
+ currentPathname: currentPath,
199
+ targetPathname: targetPathInCurrentApp,
200
+ basePath: basename,
201
+ adminRoutePath: getTopbarAdminRoutePath(app),
202
+ });
203
+
204
+ return (
205
+ <a
206
+ href={href}
207
+ target={shouldOpenInNewWindow ? '_blank' : undefined}
208
+ rel={shouldOpenInNewWindow ? 'noopener noreferrer' : undefined}
209
+ >
210
+ {props.title}
211
+ </a>
212
+ );
213
+ }
139
214
 
140
- if (isAdminRuntimePath(currentPath)) {
141
- return <Link to={targetPath}>{props.title}</Link>;
215
+ if (isAdminRuntimePath(currentRoutePath)) {
216
+ return <Link to={targetPathInCurrentApp}>{props.title}</Link>;
142
217
  }
143
218
 
144
219
  return (
@@ -0,0 +1,27 @@
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
+ export const ROUTE_TRANSIENT_INPUT_ARGS_KEY = '__nocobaseOpenViewInputArgs';
11
+
12
+ export type RouteTransientInputArgsState = {
13
+ [ROUTE_TRANSIENT_INPUT_ARGS_KEY]?: Record<string, Record<string, unknown>>;
14
+ usr?: RouteTransientInputArgsState;
15
+ };
16
+
17
+ export const getRouteTransientInputArgs = (state: unknown, viewUid?: string) => {
18
+ if (!viewUid || !state || typeof state !== 'object') {
19
+ return {};
20
+ }
21
+
22
+ const stateValue = state as RouteTransientInputArgsState;
23
+ const values = (stateValue[ROUTE_TRANSIENT_INPUT_ARGS_KEY] || stateValue.usr?.[ROUTE_TRANSIENT_INPUT_ARGS_KEY])?.[
24
+ viewUid
25
+ ];
26
+ return values && typeof values === 'object' ? values : {};
27
+ };
@@ -207,6 +207,48 @@ describe('dateTimeFormat', () => {
207
207
  expect(save).toHaveBeenCalled();
208
208
  });
209
209
 
210
+ it('syncs ordinary table column props when date time format settings are saved', async () => {
211
+ const setProps = vi.fn();
212
+ const save = vi.fn();
213
+ const setParentProps = vi.fn();
214
+ const model = {
215
+ context: {
216
+ collectionField: {
217
+ type: 'datetime',
218
+ interface: 'datetime',
219
+ },
220
+ },
221
+ setProps,
222
+ save,
223
+ parent: {
224
+ use: 'TableColumnModel',
225
+ setProps: setParentProps,
226
+ },
227
+ };
228
+ model.parent['subModels'] = {
229
+ field: model,
230
+ };
231
+
232
+ await dateTimeFormat.beforeParamsSave(
233
+ { model },
234
+ {
235
+ picker: 'date',
236
+ dateFormat: 'YYYY-MM-DD',
237
+ showTime: true,
238
+ timeFormat: 'HH:mm:ss',
239
+ },
240
+ );
241
+
242
+ expect(setParentProps).toHaveBeenCalledWith({
243
+ picker: 'date',
244
+ dateFormat: 'YYYY-MM-DD',
245
+ showTime: true,
246
+ timeFormat: 'HH:mm:ss',
247
+ format: 'YYYY-MM-DD HH:mm:ss',
248
+ });
249
+ expect(save).toHaveBeenCalled();
250
+ });
251
+
210
252
  it('hides time format for association title date-only fields', () => {
211
253
  const ctx = {
212
254
  model: {
@@ -105,9 +105,6 @@ function resolveItemDependencyPath(ctx: FlowContext, depPath: NamePath): DataSco
105
105
  ctx,
106
106
  parseFieldIndexEntries((ctx.model as any)?.context?.fieldIndex ?? (ctx as any)?.fieldIndex),
107
107
  );
108
- if (!entries.length) {
109
- return wildcardDeps();
110
- }
111
108
 
112
109
  let parentDepth = 0;
113
110
  let cursor = [...depPath];
@@ -121,6 +118,10 @@ function resolveItemDependencyPath(ctx: FlowContext, depPath: NamePath): DataSco
121
118
  return wildcardDeps();
122
119
  }
123
120
 
121
+ if (!entries.length) {
122
+ return parentDepth === 0 ? resolveRootItemDependencyPath(cursor) : emptyDeps();
123
+ }
124
+
124
125
  if (parentDepth === entries.length) {
125
126
  return resolveRootItemDependencyPath(cursor);
126
127
  }
@@ -231,7 +231,7 @@ export const FIELDS_VALIDATION_OPTIONS = {
231
231
  },
232
232
  {
233
233
  key: 'multiple',
234
- label: 'Multiple',
234
+ label: 'Multiple of',
235
235
  hasValue: true,
236
236
  params: [{ key: 'base', label: 'Base', componentType: 'inputNumber', required: true }],
237
237
  },
@@ -18,6 +18,7 @@ export enum NocoBaseDesktopRouteType {
18
18
 
19
19
  export interface NocoBaseDesktopRouteOptions {
20
20
  hasPersistedMenuInstanceFlow?: boolean;
21
+ hasPersistedPageTabFlowModel?: boolean;
21
22
  [key: string]: any;
22
23
  }
23
24
 
package/src/index.ts CHANGED
@@ -30,6 +30,8 @@ export * from './layout-manager';
30
30
  export * from './hooks';
31
31
  export { default as languageCodes } from './locale/languageCodes';
32
32
  export * from './nocobase-buildin-plugin';
33
+ export { getRouteRuntimeVersion } from './utils/getRouteRuntimeVersion';
34
+ export type { RouteRuntimeVersion } from './utils/getRouteRuntimeVersion';
33
35
  export * from './collection-field-interface/CollectionFieldInterface';
34
36
  export * from './collection-field-interface/CollectionFieldInterfaceManager';
35
37
  export * from './collection-manager/field-configure';
@@ -38,7 +40,10 @@ export * from './collection-manager/filter-operators';
38
40
  export * from './collection-manager/interfaces';
39
41
  export * from './collection-manager/template-fields';
40
42
  export * from './data-source';
43
+ export * from './entry-actions';
41
44
  export * from './flow';
45
+ export { CodeEditorExtension } from './flow/components/code-editor/extension';
46
+ export type { CodeEditorExtra, CodeEditorExtraRegistry, EditorRef } from './flow/components/code-editor/types';
42
47
  export {
43
48
  DEFAULT_DATA_SOURCE_KEY,
44
49
  IconPicker,
@@ -47,4 +52,6 @@ export {
47
52
  NocoBaseDesktopRouteType,
48
53
  } from './flow-compat';
49
54
  export type { NocoBaseDesktopRoute } from './flow-compat';
55
+ export * from './utils/markdownSanitize';
56
+ export * from './ui-operation';
50
57
  export { default as AntdAppProvider } from './theme/AntdAppProvider';
@@ -38,11 +38,12 @@ export const LayoutContentRoute = (props: LayoutContentRouteProps) => {
38
38
  id: lastMatch?.id,
39
39
  name: lastMatch?.id,
40
40
  pathname: location.pathname,
41
+ state: location.state,
41
42
  params: (lastMatch?.params || {}) as Record<string, string | undefined>,
42
43
  layoutRouteName: layout.routeName,
43
44
  layoutBasePathname: layoutMatch?.pathname,
44
45
  };
45
- }, [layout.routeName, location.pathname, matches]);
46
+ }, [layout.routeName, location.pathname, location.state, matches]);
46
47
  if (!model) {
47
48
  throw new Error(`[NocoBase] Layout '${layout.routeName}' model '${layout.uid}' is not mounted.`);
48
49
  }
@@ -71,11 +71,12 @@ export const LayoutRoute = (props: LayoutRouteProps) => {
71
71
  id: lastMatch?.id,
72
72
  name: lastMatch?.id,
73
73
  pathname: location.pathname,
74
+ state: location.state,
74
75
  params: lastMatchParams,
75
76
  layoutRouteName: layout.routeName,
76
77
  layoutBasePathname: layoutMatch?.pathname,
77
78
  };
78
- }, [lastMatch?.id, lastMatchParams, layout.routeName, layoutMatch?.pathname, location.pathname]);
79
+ }, [lastMatch?.id, lastMatchParams, layout.routeName, layoutMatch?.pathname, location.pathname, location.state]);
79
80
  const { loading, data, error } = useRequest(
80
81
  async () => {
81
82
  const existingModel = flowEngine.getModel<BaseLayoutModel>(layout.uid);
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  import { FlowEngine, FlowEngineProvider, observer } from '@nocobase/flow-engine';
11
- import { render, screen, waitFor } from '@testing-library/react';
11
+ import { act, render, screen, waitFor } from '@testing-library/react';
12
12
  import React from 'react';
13
13
  import { createMemoryRouter, Outlet, RouterProvider, useOutlet } from 'react-router-dom';
14
14
  import { describe, expect, it, vi } from 'vitest';
@@ -106,6 +106,64 @@ describe('LayoutRoute', () => {
106
106
  });
107
107
  });
108
108
 
109
+ it('syncs updated router state when navigating to the same layout pathname', async () => {
110
+ const syncLayoutRoute = vi.fn();
111
+
112
+ class StateTrackingLayoutModel extends TestLayoutModel {
113
+ syncLayoutRoute(routeLike: Parameters<BaseLayoutModel['syncLayoutRoute']>[0]) {
114
+ syncLayoutRoute(routeLike);
115
+ return super.syncLayoutRoute(routeLike);
116
+ }
117
+ }
118
+
119
+ const stateTrackingLayout: LayoutDefinition = {
120
+ ...layout,
121
+ layoutModelClass: 'StateTrackingLayoutModel',
122
+ };
123
+ const engine = new FlowEngine();
124
+ engine.registerModels({ StateTrackingLayoutModel });
125
+ engine.context.defineProperty('app', {
126
+ value: {
127
+ layoutManager: {
128
+ getLayout: () => stateTrackingLayout,
129
+ },
130
+ },
131
+ });
132
+
133
+ const router = createMemoryRouter(
134
+ [
135
+ {
136
+ id: layout.routeName,
137
+ path: layout.routePath,
138
+ element: <LayoutRoute layoutRouteName="test" />,
139
+ },
140
+ ],
141
+ {
142
+ initialEntries: ['/test'],
143
+ },
144
+ );
145
+
146
+ render(
147
+ <FlowEngineProvider engine={engine}>
148
+ <RouterProvider router={router} />
149
+ </FlowEngineProvider>,
150
+ );
151
+
152
+ expect(await screen.findByTestId('layout-route')).toHaveTextContent('test');
153
+ syncLayoutRoute.mockClear();
154
+
155
+ const routeState = {
156
+ __nocobaseOpenViewInputArgs: { popup: { formData: { status: 'todo' } } },
157
+ };
158
+ await act(async () => {
159
+ await router.navigate('/test', { state: routeState });
160
+ });
161
+
162
+ await waitFor(() => {
163
+ expect(syncLayoutRoute).toHaveBeenCalledWith(expect.objectContaining({ state: routeState }));
164
+ });
165
+ });
166
+
109
167
  it('does not activate desktop route loading for generic layouts', async () => {
110
168
  const activateLayout = vi.fn(() => vi.fn());
111
169
  const engine = new FlowEngine();
@@ -413,6 +471,34 @@ describe('LayoutContentRoute', () => {
413
471
  });
414
472
  });
415
473
 
474
+ it('syncs updated router state when navigating to the same content pathname', async () => {
475
+ const syncLayoutRoute = vi.fn();
476
+
477
+ class StateTrackingLayoutModel extends TestLayoutModel {
478
+ syncLayoutRoute(routeLike: Parameters<BaseLayoutModel['syncLayoutRoute']>[0]) {
479
+ syncLayoutRoute(routeLike);
480
+ return super.syncLayoutRoute(routeLike);
481
+ }
482
+ }
483
+
484
+ const { router } = setup('/test/page-1/view/popup', layout, StateTrackingLayoutModel);
485
+ await waitFor(() => {
486
+ expect(syncLayoutRoute).toHaveBeenCalled();
487
+ });
488
+ syncLayoutRoute.mockClear();
489
+
490
+ const routeState = {
491
+ __nocobaseOpenViewInputArgs: { popup: { formData: { status: 'todo' } } },
492
+ };
493
+ await act(async () => {
494
+ await router.navigate('/test/page-1/view/popup', { state: routeState });
495
+ });
496
+
497
+ await waitFor(() => {
498
+ expect(syncLayoutRoute).toHaveBeenCalledWith(expect.objectContaining({ state: routeState }));
499
+ });
500
+ });
501
+
416
502
  it('parses nested layout route by matched layout pathname', async () => {
417
503
  const nestedLayout: LayoutDefinition = {
418
504
  ...layout,
@@ -54,6 +54,7 @@ export const languageCodes: Record<string, LocaleOptions> = {
54
54
  'ml-IN': { label: 'മലയാളം' },
55
55
  'mn-MN': { label: 'Монгол хэл' },
56
56
  'ms-MY': { label: 'بهاس ملايو' },
57
+ 'my-MM': { label: 'မြန်မာဘာသာ' },
57
58
  'nb-NO': { label: 'Norsk bokmål' },
58
59
  'ne-NP': { label: 'नेपाली' },
59
60
  'nl-BE': { label: 'Vlaams' },
@@ -73,7 +74,8 @@ export const languageCodes: Record<string, LocaleOptions> = {
73
74
  'tk-TK': { label: 'Turkmen' },
74
75
  'tr-TR': { label: 'Türkçe' },
75
76
  'uk-UA': { label: 'Українська' },
76
- 'ur-PK': { label: 'Oʻzbekcha' },
77
+ 'ur-PK': { label: 'اردو' },
78
+ 'uz-UZ': { label: 'Oʻzbekcha' },
77
79
  'vi-VN': { label: 'Tiếng Việt' },
78
80
  'zh-CN': { label: '简体中文' },
79
81
  'zh-HK': { label: '繁體中文(香港)' },
@@ -15,7 +15,12 @@ import type { Application } from '../Application';
15
15
  import { getCurrentV2RedirectPath, getDefaultV2AdminRedirectPath } from '../authRedirect';
16
16
  import { AppNotFound } from '../components';
17
17
  import { PluginFlowEngine } from '../flow';
18
- import { ADMIN_LAYOUT_MODEL_UID, AdminLayoutMenuItemModel, AdminLayoutModel } from '../flow/admin-shell/admin-layout';
18
+ import {
19
+ ADMIN_LAYOUT_MODEL_UID,
20
+ AdminLayoutMenuItemModel,
21
+ AdminLayoutModel,
22
+ AppSwitcherActionPanelModel,
23
+ } from '../flow/admin-shell/admin-layout';
19
24
  import { useApp } from '../hooks/useApp';
20
25
  import { Plugin } from '../Plugin';
21
26
  import { AdminSettingsLayoutModel } from '../settings-center';
@@ -235,6 +240,16 @@ const CurrentUserProvider: FC = ({ children }) => {
235
240
  return;
236
241
  }
237
242
 
243
+ try {
244
+ await app.apiClient.auth.syncCookies();
245
+ } catch {
246
+ // Cookie bootstrap is best-effort; auth:check remains the source of truth for the current page load.
247
+ }
248
+
249
+ if (!mounted) {
250
+ return;
251
+ }
252
+
238
253
  const userMeta = createCollectionContextMeta(
239
254
  () => app.flowEngine.context.dataSourceManager?.getDataSource('main')?.getCollection('users') || null,
240
255
  app.flowEngine.translate('Current user'),
@@ -293,6 +308,8 @@ const CurrentUserProvider: FC = ({ children }) => {
293
308
  return <CurrentUserContext.Provider value={contextValue}>{children}</CurrentUserContext.Provider>;
294
309
  };
295
310
 
311
+ CurrentUserProvider.displayName = 'CurrentUserProvider';
312
+
296
313
  const RootRedirect: FC = () => {
297
314
  const app = useApp<Application>();
298
315
  const hasToken = !!app?.apiClient?.auth?.token;
@@ -326,6 +343,7 @@ export class NocoBaseBuildInPlugin extends Plugin<any, Application> {
326
343
  this.app.flowEngine.registerModels({
327
344
  AdminLayoutModel,
328
345
  AdminLayoutMenuItemModel,
346
+ AppSwitcherActionPanelModel,
329
347
  AdminSettingsLayoutModel,
330
348
  });
331
349
  this.app.layoutManager.registerLayout({
@@ -14,7 +14,7 @@ import { FlowModelRenderer, useFlowEngine } from '@nocobase/flow-engine';
14
14
  import { Layout, Menu, Result, theme } from 'antd';
15
15
  import React, { useEffect, useMemo, useRef } from 'react';
16
16
  import { useTranslation } from 'react-i18next';
17
- import { Navigate, Outlet, useLocation, useNavigate, useParams } from 'react-router-dom';
17
+ import { generatePath, Navigate, Outlet, useLocation, useNavigate, useParams } from 'react-router-dom';
18
18
  import { useACLRoleContext } from '../acl';
19
19
  import { ADMIN_SETTINGS_PATH, type PluginSettingsPageType } from '../PluginSettingsManager';
20
20
  import { useApp } from '../hooks/useApp';
@@ -68,6 +68,9 @@ export const InternalAdminSettingsLayout = () => {
68
68
  const navigate = useNavigate();
69
69
  const location = useLocation();
70
70
  const params = useParams();
71
+ const routeParams = Object.fromEntries(
72
+ Object.entries(params).filter((entry): entry is [string, string] => typeof entry[1] === 'string'),
73
+ );
71
74
  const { token } = theme.useToken();
72
75
  const { t } = useTranslation();
73
76
  const { snippets = [] } = useACLRoleContext();
@@ -174,7 +177,25 @@ export const InternalAdminSettingsLayout = () => {
174
177
  return <SettingsEmpty type="route" />;
175
178
  }
176
179
 
177
- if (!currentVisibleSetting && currentSetting.isAllow === false) {
180
+ if (currentSetting.isAllow === false) {
181
+ const firstVisibleTabPath = currentVisibleTabs
182
+ .map((tab) => getDefaultSettingsPath([tab]))
183
+ .filter((path): path is string => typeof path === 'string')
184
+ .map((path) => {
185
+ try {
186
+ return generatePath(path, routeParams);
187
+ } catch {
188
+ return null;
189
+ }
190
+ })
191
+ .find((path): path is string => typeof path === 'string');
192
+ if (firstVisibleTabPath) {
193
+ return <Navigate replace to={firstVisibleTabPath} />;
194
+ }
195
+ if (!defaultSettingsPath) {
196
+ return <Navigate replace to="/admin" />;
197
+ }
198
+
178
199
  return <SettingsEmpty type="route" />;
179
200
  }
180
201
 
@@ -0,0 +1,33 @@
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 {
11
+ decodeUIOperation as decode,
12
+ encodeUIOperation as encode,
13
+ parseUIOperation as parse,
14
+ removeUIOperation,
15
+ UI_OPERATION_QUERY_KEY,
16
+ type UIOperation,
17
+ } from '@nocobase/shared';
18
+ import { browserUIOperationCodec } from './ui-operation-codec';
19
+
20
+ export function parseUIOperation(search: string): UIOperation | undefined {
21
+ return parse(search, browserUIOperationCodec);
22
+ }
23
+
24
+ export function decodeUIOperation(encoded: string): UIOperation | undefined {
25
+ return decode(encoded, browserUIOperationCodec);
26
+ }
27
+
28
+ export function encodeUIOperation(operation: UIOperation): string {
29
+ return encode(operation, browserUIOperationCodec);
30
+ }
31
+
32
+ export { browserUIOperationCodec, removeUIOperation, UI_OPERATION_QUERY_KEY };
33
+ export type { UIOperation };
@@ -0,0 +1,54 @@
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 type { UIOperationCodec } from '@nocobase/shared';
11
+
12
+ const base64UrlPattern = /^[A-Za-z0-9_-]*$/;
13
+ const utf8Encoder = new TextEncoder();
14
+ const utf8Decoder = new TextDecoder('utf-8', { fatal: true });
15
+
16
+ function bytesToBinaryString(bytes: Uint8Array): string {
17
+ let result = '';
18
+ for (const byte of bytes) {
19
+ result += String.fromCharCode(byte);
20
+ }
21
+ return result;
22
+ }
23
+
24
+ function binaryStringToBytes(value: string): Uint8Array {
25
+ const bytes = new Uint8Array(value.length);
26
+ for (let index = 0; index < value.length; index += 1) {
27
+ bytes[index] = value.charCodeAt(index);
28
+ }
29
+ return bytes;
30
+ }
31
+
32
+ function encodeBrowserUIOperation(value: string): string {
33
+ return btoa(bytesToBinaryString(utf8Encoder.encode(value)))
34
+ .replace(/\+/g, '-')
35
+ .replace(/\//g, '_')
36
+ .replace(/=+$/, '');
37
+ }
38
+
39
+ export const browserUIOperationCodec: UIOperationCodec = {
40
+ encode: encodeBrowserUIOperation,
41
+ decode(value) {
42
+ if (!base64UrlPattern.test(value) || value.length % 4 === 1) {
43
+ return undefined;
44
+ }
45
+
46
+ try {
47
+ const paddedValue = `${value.replace(/-/g, '+').replace(/_/g, '/')}${'='.repeat((4 - (value.length % 4)) % 4)}`;
48
+ const decoded = utf8Decoder.decode(binaryStringToBytes(atob(paddedValue)));
49
+ return encodeBrowserUIOperation(decoded) === value ? decoded : undefined;
50
+ } catch {
51
+ return undefined;
52
+ }
53
+ },
54
+ };