openxiangda 1.0.3 → 1.0.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openxiangda",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "OpenXiangda CLI, workspace build tools, runtime SDK, and form components.",
5
5
  "private": false,
6
6
  "bin": {
@@ -1108,6 +1108,7 @@ var createPageSdk = (context) => {
1108
1108
  var import_cssinjs = require("@ant-design/cssinjs");
1109
1109
  var import_antd = require("antd");
1110
1110
  var import_zh_CN = __toESM(require("antd/locale/zh_CN.js"));
1111
+ var import_react3 = __toESM(require("react"));
1111
1112
  var import_client2 = require("react-dom/client");
1112
1113
 
1113
1114
  // packages/sdk/src/runtime/react/provider.tsx
@@ -1176,6 +1177,16 @@ var NAMESPACE_ROOT_CLASS = "sy-app-workspace";
1176
1177
  var RUNTIME_PORTAL_ATTR = "data-sy-runtime-portal";
1177
1178
  var PORTAL_CONTAINER_STACK_GLOBAL = "__OPENXIANGDA_PORTAL_CONTAINER_STACK__";
1178
1179
  var PORTAL_CONTAINER_RESOLVER_GLOBAL = "__OPENXIANGDA_GET_PORTAL_CONTAINER__";
1180
+ var MESSAGE_PROXY_GLOBAL = "__OPENXIANGDA_ANTD_MESSAGE_PROXY__";
1181
+ var MESSAGE_METHODS = [
1182
+ "open",
1183
+ "success",
1184
+ "info",
1185
+ "warning",
1186
+ "error",
1187
+ "loading",
1188
+ "destroy"
1189
+ ];
1179
1190
  var createRuntimeRoot = (el) => {
1180
1191
  return (0, import_client2.createRoot)(el);
1181
1192
  };
@@ -1224,6 +1235,46 @@ var createPortalContainer = (el) => {
1224
1235
  parent.appendChild(portalContainer);
1225
1236
  return portalContainer;
1226
1237
  };
1238
+ var getAntdMessageProxyState = () => {
1239
+ const globalScope = globalThis;
1240
+ if (!globalScope[MESSAGE_PROXY_GLOBAL]) {
1241
+ globalScope[MESSAGE_PROXY_GLOBAL] = {
1242
+ apiStack: [],
1243
+ installed: false,
1244
+ originalMethods: {}
1245
+ };
1246
+ }
1247
+ return globalScope[MESSAGE_PROXY_GLOBAL];
1248
+ };
1249
+ var installAntdMessageProxy = () => {
1250
+ const state = getAntdMessageProxyState();
1251
+ if (state.installed) return state;
1252
+ MESSAGE_METHODS.forEach((method) => {
1253
+ const originalMethod = import_antd.message[method];
1254
+ if (typeof originalMethod !== "function") return;
1255
+ state.originalMethods[method] = originalMethod.bind(import_antd.message);
1256
+ import_antd.message[method] = (...args) => {
1257
+ const api = state.apiStack.at(-1);
1258
+ const apiMethod = api?.[method];
1259
+ if (typeof apiMethod === "function") {
1260
+ return apiMethod(...args);
1261
+ }
1262
+ return state.originalMethods[method]?.(...args);
1263
+ };
1264
+ });
1265
+ state.installed = true;
1266
+ return state;
1267
+ };
1268
+ var registerAntdMessageApi = (api) => {
1269
+ const state = installAntdMessageProxy();
1270
+ state.apiStack.push(api);
1271
+ return () => {
1272
+ const position = state.apiStack.lastIndexOf(api);
1273
+ if (position >= 0) {
1274
+ state.apiStack.splice(position, 1);
1275
+ }
1276
+ };
1277
+ };
1227
1278
  var installRuntimePortalContainer = (el) => {
1228
1279
  const globalScope = globalThis;
1229
1280
  const portalContainer = createPortalContainer(el);
@@ -1251,6 +1302,11 @@ var installRuntimePortalContainer = (el) => {
1251
1302
  };
1252
1303
  };
1253
1304
  var installAntdStaticHolder = (el, portalContainer) => {
1305
+ installAntdMessageProxy();
1306
+ const getMessageContainer = () => {
1307
+ if (portalContainer?.isConnected) return portalContainer;
1308
+ return getRuntimeRoot(el);
1309
+ };
1254
1310
  import_antd.ConfigProvider.config({
1255
1311
  prefixCls: "sy-ant",
1256
1312
  iconPrefixCls: "sy-anticon",
@@ -1271,6 +1327,19 @@ var installAntdStaticHolder = (el, portalContainer) => {
1271
1327
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_cssinjs.StyleProvider, { hashPriority: "high", container: getStyleContainer(el), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_antd.ConfigProvider, { ...createAntdConfig(overlayContainer), children }) });
1272
1328
  }
1273
1329
  });
1330
+ import_antd.message.config({
1331
+ prefixCls: "sy-ant-message",
1332
+ getContainer: getMessageContainer
1333
+ });
1334
+ };
1335
+ var RuntimeMessageBridge = ({ children }) => {
1336
+ const appContext = import_antd.App.useApp();
1337
+ import_react3.default.useLayoutEffect(() => {
1338
+ return registerAntdMessageApi(
1339
+ appContext.message
1340
+ );
1341
+ }, [appContext.message]);
1342
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
1274
1343
  };
1275
1344
  var createReactPage = (AppComponent) => {
1276
1345
  let root = null;
@@ -1292,7 +1361,7 @@ var createReactPage = (AppComponent) => {
1292
1361
  installAntdStaticHolder(el, portalContainer);
1293
1362
  const antdConfig = createAntdConfig(overlayContainer);
1294
1363
  root.render(
1295
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_cssinjs.StyleProvider, { hashPriority: "high", container: getStyleContainer(el), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_antd.ConfigProvider, { ...antdConfig, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_antd.App, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PageProvider, { context, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AppComponent, {}) }) }) }) })
1364
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_cssinjs.StyleProvider, { hashPriority: "high", container: getStyleContainer(el), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_antd.ConfigProvider, { ...antdConfig, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_antd.App, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RuntimeMessageBridge, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PageProvider, { context, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AppComponent, {}) }) }) }) }) })
1296
1365
  );
1297
1366
  };
1298
1367
  return {
@@ -1314,7 +1383,7 @@ var createReactPage = (AppComponent) => {
1314
1383
  };
1315
1384
 
1316
1385
  // packages/sdk/src/runtime/react/hooks/useCurrentUser.ts
1317
- var import_react3 = require("react");
1386
+ var import_react4 = require("react");
1318
1387
 
1319
1388
  // packages/sdk/src/runtime/react/hooks/usePageContext.ts
1320
1389
  var usePageContext = () => {
@@ -1324,7 +1393,7 @@ var usePageContext = () => {
1324
1393
  // packages/sdk/src/runtime/react/hooks/useCurrentUser.ts
1325
1394
  var useCurrentUser = () => {
1326
1395
  const { user } = usePageContext();
1327
- return (0, import_react3.useMemo)(() => {
1396
+ return (0, import_react4.useMemo)(() => {
1328
1397
  const userType = user.userType === "guest" || user.isGuest ? "guest" : "normal";
1329
1398
  const isGuest = userType === "guest";
1330
1399
  return {
@@ -1342,7 +1411,7 @@ var useCurrentUser = () => {
1342
1411
  };
1343
1412
 
1344
1413
  // packages/sdk/src/runtime/react/hooks/useDataSource.ts
1345
- var import_react4 = require("react");
1414
+ var import_react5 = require("react");
1346
1415
 
1347
1416
  // packages/sdk/src/runtime/react/hooks/usePageSdk.ts
1348
1417
  var usePageSdk = () => {
@@ -1360,19 +1429,19 @@ var createParamsSignature = (value) => {
1360
1429
  var useDataSource = (name, options = {}) => {
1361
1430
  const sdk = usePageSdk();
1362
1431
  const { params, immediate = true, transform } = options;
1363
- const paramsRef = (0, import_react4.useRef)(params);
1364
- const transformRef = (0, import_react4.useRef)(transform);
1432
+ const paramsRef = (0, import_react5.useRef)(params);
1433
+ const transformRef = (0, import_react5.useRef)(transform);
1365
1434
  const paramsSignature = createParamsSignature(params);
1366
- const [response, setResponse] = (0, import_react4.useState)(
1435
+ const [response, setResponse] = (0, import_react5.useState)(
1367
1436
  null
1368
1437
  );
1369
- const [result, setResult] = (0, import_react4.useState)(null);
1370
- const [data, setData] = (0, import_react4.useState)(null);
1371
- const [loading, setLoading] = (0, import_react4.useState)(false);
1372
- const [error, setError] = (0, import_react4.useState)(null);
1438
+ const [result, setResult] = (0, import_react5.useState)(null);
1439
+ const [data, setData] = (0, import_react5.useState)(null);
1440
+ const [loading, setLoading] = (0, import_react5.useState)(false);
1441
+ const [error, setError] = (0, import_react5.useState)(null);
1373
1442
  paramsRef.current = params;
1374
1443
  transformRef.current = transform;
1375
- const run = (0, import_react4.useCallback)(
1444
+ const run = (0, import_react5.useCallback)(
1376
1445
  async (overrideParams) => {
1377
1446
  setLoading(true);
1378
1447
  setError(null);
@@ -1399,7 +1468,7 @@ var useDataSource = (name, options = {}) => {
1399
1468
  },
1400
1469
  [name, sdk.dataSource]
1401
1470
  );
1402
- (0, import_react4.useEffect)(() => {
1471
+ (0, import_react5.useEffect)(() => {
1403
1472
  if (!immediate) {
1404
1473
  return;
1405
1474
  }
@@ -1420,7 +1489,7 @@ var useDataSource = (name, options = {}) => {
1420
1489
  };
1421
1490
 
1422
1491
  // packages/sdk/src/runtime/react/hooks/useFormViewPermissions.ts
1423
- var import_react5 = require("react");
1492
+ var import_react6 = require("react");
1424
1493
  var EMPTY_SUMMARY = {
1425
1494
  fieldPermissions: {},
1426
1495
  operations: []
@@ -1436,12 +1505,12 @@ var toError = (error) => {
1436
1505
  };
1437
1506
  var useFormViewPermissions = (formUuid, options = {}) => {
1438
1507
  const sdk = usePageSdk();
1439
- const [summary, setSummary] = (0, import_react5.useState)(EMPTY_SUMMARY);
1440
- const [response, setResponse] = (0, import_react5.useState)(null);
1441
- const [loading, setLoading] = (0, import_react5.useState)(false);
1442
- const [error, setError] = (0, import_react5.useState)(null);
1508
+ const [summary, setSummary] = (0, import_react6.useState)(EMPTY_SUMMARY);
1509
+ const [response, setResponse] = (0, import_react6.useState)(null);
1510
+ const [loading, setLoading] = (0, import_react6.useState)(false);
1511
+ const [error, setError] = (0, import_react6.useState)(null);
1443
1512
  const immediate = options.immediate ?? true;
1444
- const refresh = (0, import_react5.useCallback)(async () => {
1513
+ const refresh = (0, import_react6.useCallback)(async () => {
1445
1514
  const normalizedFormUuid = String(formUuid || "").trim();
1446
1515
  if (!normalizedFormUuid) {
1447
1516
  setSummary(EMPTY_SUMMARY);
@@ -1472,21 +1541,21 @@ var useFormViewPermissions = (formUuid, options = {}) => {
1472
1541
  setLoading(false);
1473
1542
  }
1474
1543
  }, [formUuid, options.appType, sdk]);
1475
- (0, import_react5.useEffect)(() => {
1544
+ (0, import_react6.useEffect)(() => {
1476
1545
  if (!immediate) {
1477
1546
  return;
1478
1547
  }
1479
1548
  void refresh();
1480
1549
  }, [immediate, refresh]);
1481
- const operationSet = (0, import_react5.useMemo)(
1550
+ const operationSet = (0, import_react6.useMemo)(
1482
1551
  () => new Set(summary.operations),
1483
1552
  [summary.operations]
1484
1553
  );
1485
- const can = (0, import_react5.useCallback)(
1554
+ const can = (0, import_react6.useCallback)(
1486
1555
  (operation) => operationSet.has(operation),
1487
1556
  [operationSet]
1488
1557
  );
1489
- const getFieldPermission = (0, import_react5.useCallback)(
1558
+ const getFieldPermission = (0, import_react6.useCallback)(
1490
1559
  (fieldName) => summary.fieldPermissions[fieldName] || null,
1491
1560
  [summary.fieldPermissions]
1492
1561
  );