@done-coding/forge-core 0.100.2-alpha.0 → 0.100.3-alpha.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.
@@ -0,0 +1,111 @@
1
+ const BEHAVIOR_DEFAULT_EVENTS = Object.freeze([
2
+ "action-click",
3
+ "confirm-open",
4
+ "confirm-close",
5
+ "nest-list-remove",
6
+ "table-selection-change",
7
+ "table-row-select",
8
+ "table-export",
9
+ "table-view-toggle",
10
+ "menu-select"
11
+ ]);
12
+ const behaviorDataFields = {
13
+ "action-click": ["type", "key", "index", "rowKey"],
14
+ "confirm-open": ["type", "key", "index", "rowKey"],
15
+ "confirm-close": ["type", "key", "index", "rowKey", "confirmed"],
16
+ search: ["type"],
17
+ "search-toggle": ["collapsed"],
18
+ "nest-list-add": ["count"],
19
+ "nest-list-remove": ["index"],
20
+ "table-page-change": ["currentPage"],
21
+ "table-size-change": ["pageSize"],
22
+ "table-selection-change": ["count"],
23
+ "table-row-select": ["rowKey", "selected"],
24
+ "table-scroll": ["scrollTop", "scrollLeft"],
25
+ "table-export": ["type"],
26
+ "table-view-toggle": ["custom"],
27
+ "dataview-selection-change": ["count"],
28
+ "dataview-row-select": ["rowKey", "selected"],
29
+ "datagrid-selection-change": ["count"],
30
+ "datagrid-row-select": ["rowKey", "selected"],
31
+ "auto-refresh-toggle": ["enabled", "interval"],
32
+ "tab-change": ["key", "index"],
33
+ "menu-select": ["path"],
34
+ "modal-open": ["nsKey", "key"],
35
+ "modal-close": ["nsKey", "key"],
36
+ "modal-update": ["nsKey", "key"],
37
+ "body-scroll": ["scrollTop"],
38
+ "sidebar-toggle": ["collapsed"],
39
+ "aside-toggle": ["collapsed"]
40
+ };
41
+ function behaviorContextSnapshot(context) {
42
+ return {
43
+ ...context.page ? {
44
+ page: {
45
+ path: context.page.path,
46
+ ...context.page.name === void 0 ? {} : { name: context.page.name }
47
+ }
48
+ } : {},
49
+ actor: { kind: context.actor.kind, id: context.actor.id },
50
+ sessionId: context.sessionId,
51
+ ...context.experiments ? { experiments: { ...context.experiments } } : {}
52
+ };
53
+ }
54
+ function createBehaviorPort(bridge, options) {
55
+ let disposed = false;
56
+ const selected = new Set(options.events ?? BEHAVIOR_DEFAULT_EVENTS);
57
+ const send = (record) => {
58
+ if (disposed || !bridge) return;
59
+ try {
60
+ const context = behaviorContextSnapshot(options.context());
61
+ if (disposed) return;
62
+ const result = options.send({ ...record, context });
63
+ if (result) result.catch(() => {
64
+ });
65
+ } catch {
66
+ }
67
+ };
68
+ const onEvent = (event) => {
69
+ const raw = event.data;
70
+ const data = {};
71
+ for (const key of behaviorDataFields[event.event] ?? []) {
72
+ const value = raw == null ? void 0 : raw[key];
73
+ if (typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))
74
+ data[key] = value;
75
+ }
76
+ const button = event.submodule === "action-btn";
77
+ const trackKey = button && typeof (raw == null ? void 0 : raw.trackKey) === "string" ? raw.trackKey : void 0;
78
+ const source = button && ((raw == null ? void 0 : raw.source) === "standalone" || (raw == null ? void 0 : raw.source) === "group") ? raw.source : void 0;
79
+ send({
80
+ kind: "action",
81
+ event: event.event,
82
+ origin: BEHAVIOR_DEFAULT_EVENTS.includes(event.event) ? "user" : "unverified",
83
+ data,
84
+ ...trackKey === void 0 ? {} : { trackKey },
85
+ ...source === void 0 ? {} : { source },
86
+ timestamp: event.timestamp
87
+ });
88
+ };
89
+ const off = selected.size ? bridge == null ? void 0 : bridge.onEvent(onEvent, (event) => selected.has(event.event)) : void 0;
90
+ return {
91
+ exposure(input) {
92
+ if (disposed || !bridge) return;
93
+ send({
94
+ kind: "exposure",
95
+ event: "exposure",
96
+ origin: "user",
97
+ ...input.trackKey === void 0 ? {} : { trackKey: input.trackKey },
98
+ data: { experiment: input.experiment, variant: input.variant },
99
+ timestamp: Date.now()
100
+ });
101
+ },
102
+ dispose() {
103
+ disposed = true;
104
+ off == null ? void 0 : off();
105
+ }
106
+ };
107
+ }
108
+ export {
109
+ BEHAVIOR_DEFAULT_EVENTS,
110
+ createBehaviorPort
111
+ };
@@ -12,6 +12,7 @@ import { BADGE_MASK_KINDS } from "./badge.mjs";
12
12
  import { createBridgePermissionHook } from "./permission.mjs";
13
13
  import { CORE_BRIDGE_KEY } from "../inject/key.mjs";
14
14
  import { BridgeEventName, KNOWN_BRIDGE_EVENTS } from "./contracts/event.mjs";
15
+ import { BEHAVIOR_DEFAULT_EVENTS, createBehaviorPort } from "./behavior.mjs";
15
16
  function createCoreBridge(options) {
16
17
  const rawNs = options.APP_CACHE_CONFIG.namespace;
17
18
  let effectiveNs;
@@ -322,8 +323,10 @@ function createCoreBridge(options) {
322
323
  }
323
324
  export {
324
325
  BADGE_MASK_KINDS,
326
+ BEHAVIOR_DEFAULT_EVENTS,
325
327
  BridgeEventName,
326
328
  KNOWN_BRIDGE_EVENTS,
329
+ createBehaviorPort,
327
330
  createCoreBridge,
328
331
  createGenerateRouteMetaRawTree,
329
332
  createStorageWithNamespace,
@@ -26,6 +26,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
26
26
  autoInsertSpace: { type: Boolean },
27
27
  tag: {},
28
28
  groupMeta: {},
29
+ trackKey: {},
29
30
  confirmMode: {},
30
31
  confirmConfig: {},
31
32
  beforeOpen: {},
@@ -47,6 +48,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
47
48
  } = useActionBtnReport(() => ({
48
49
  type: props.type,
49
50
  groupMeta: props.groupMeta,
51
+ trackKey: props.trackKey,
50
52
  config: resolvedConfig.value
51
53
  }));
52
54
  let lastEvt;
@@ -10,6 +10,8 @@ function useActionBtnReport(get) {
10
10
  const state = get();
11
11
  return {
12
12
  ...state.groupMeta,
13
+ source: state.groupMeta ? "group" : "standalone",
14
+ ...state.trackKey === void 0 ? {} : { trackKey: state.trackKey },
13
15
  type: ((_a = state.config) == null ? void 0 : _a.type) ?? state.type,
14
16
  confirmed
15
17
  };
@@ -17,11 +19,15 @@ function useActionBtnReport(get) {
17
19
  };
18
20
  return {
19
21
  reportActionClick() {
20
- if (get().groupMeta)
21
- report("action-click", () => ({
22
- ...get().groupMeta,
23
- type: get().type
24
- }));
22
+ report("action-click", () => {
23
+ const state = get();
24
+ return {
25
+ ...state.groupMeta,
26
+ source: state.groupMeta ? "group" : "standalone",
27
+ ...state.trackKey === void 0 ? {} : { trackKey: state.trackKey },
28
+ type: state.type
29
+ };
30
+ });
25
31
  },
26
32
  reportConfirmOpen() {
27
33
  confirmCycle = {};
@@ -30,6 +36,8 @@ function useActionBtnReport(get) {
30
36
  const state = get();
31
37
  return {
32
38
  ...state.groupMeta,
39
+ source: state.groupMeta ? "group" : "standalone",
40
+ ...state.trackKey === void 0 ? {} : { trackKey: state.trackKey },
33
41
  type: ((_a = state.config) == null ? void 0 : _a.type) ?? state.type,
34
42
  title: (_b = state.config) == null ? void 0 : _b.title,
35
43
  content: (_c = state.config) == null ? void 0 : _c.content
@@ -12,7 +12,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
12
12
  setup(__props) {
13
13
  const props = __props;
14
14
  const { configs, ctx, defaultSize } = toRefs(props);
15
- const { withGroupMeta, withNativeReport } = useActionBtnGroupReport();
15
+ const { withGroupMeta, withNativeProps } = useActionBtnGroupReport();
16
16
  const AnyActionBtn = _sfc_main$1;
17
17
  const visibleConfigs = computed(
18
18
  () => (configs.value ?? []).filter(
@@ -48,7 +48,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
48
48
  }, 1040)) : (openBlock(), createBlock(unref(ElButton), mergeProps({
49
49
  key: 1,
50
50
  ref_for: true
51
- }, unref(withNativeReport)(mergeSize((_a = btn.props) == null ? void 0 : _a.call(btn, unref(ctx))), btn.key, index)), {
51
+ }, unref(withNativeProps)(mergeSize((_a = btn.props) == null ? void 0 : _a.call(btn, unref(ctx))))), {
52
52
  default: withCtx(() => [
53
53
  btn.render ? (openBlock(), createBlock(resolveDynamicComponent(btn.render), {
54
54
  key: 0,
@@ -1,29 +1,15 @@
1
- import { useBridgeReport } from "../../../hooks/use-bridge-report.mjs";
2
1
  function useActionBtnGroupReport() {
3
- const report = useBridgeReport();
4
2
  const withGroupMeta = (raw, key, index) => ({
5
3
  ...raw,
6
4
  groupMeta: { ...raw.groupMeta, key, index }
7
5
  });
8
- const withNativeReport = (raw, key, index) => {
9
- const { onClick, groupMeta, ...buttonProps } = raw;
10
- const wrap = (handler, first = true) => function(...args) {
11
- if (first && !raw.disabled && !raw.loading) {
12
- report("action-click", () => ({
13
- ...groupMeta,
14
- key,
15
- index,
16
- type: raw.type ?? "default"
17
- }));
18
- }
19
- return handler == null ? void 0 : handler.apply(this, args);
20
- };
21
- return {
22
- ...buttonProps,
23
- onClick: Array.isArray(onClick) ? onClick.length ? onClick.map((handler, i) => wrap(handler, i === 0)) : wrap() : wrap(onClick)
24
- };
6
+ const withNativeProps = (raw) => {
7
+ const buttonProps = { ...raw };
8
+ delete buttonProps.groupMeta;
9
+ delete buttonProps.trackKey;
10
+ return buttonProps;
25
11
  };
26
- return { withGroupMeta, withNativeReport };
12
+ return { withGroupMeta, withNativeProps };
27
13
  }
28
14
  export {
29
15
  useActionBtnGroupReport
@@ -10,6 +10,7 @@ import { usePermission } from "./use-permission.mjs";
10
10
  import { buildRhythmCss, useCoreThemeApply } from "./use-theme-apply.mjs";
11
11
  import { useCoreViewportApply } from "./use-viewport-apply.mjs";
12
12
  import { useBridgeReport } from "./use-bridge-report.mjs";
13
+ import { useBehaviorPort } from "./use-behavior-port.mjs";
13
14
  export {
14
15
  buildRhythmCss,
15
16
  resolveBreakpointByWidth,
@@ -17,6 +18,7 @@ export {
17
18
  useActivated,
18
19
  useActivatedEvent,
19
20
  useActivatedExec,
21
+ useBehaviorPort,
20
22
  useBreakpoint,
21
23
  useBridgeReport,
22
24
  useChannelViewportHeight,
@@ -0,0 +1,27 @@
1
+ import { inject, onScopeDispose } from "vue";
2
+ import { CORE_BRIDGE_KEY } from "../inject/key.mjs";
3
+ import { createBehaviorPort } from "../bridge/behavior.mjs";
4
+ import { useActivated } from "./activated.mjs";
5
+ function useBehaviorPort(options) {
6
+ const bridge = inject(CORE_BRIDGE_KEY, void 0);
7
+ let disposed = false;
8
+ let port = createBehaviorPort(bridge, options);
9
+ useActivated(({ isActivated }) => {
10
+ if (isActivated) {
11
+ if (!disposed && !port) port = createBehaviorPort(bridge, options);
12
+ } else {
13
+ port == null ? void 0 : port.dispose();
14
+ port = void 0;
15
+ }
16
+ });
17
+ const dispose = () => {
18
+ disposed = true;
19
+ port == null ? void 0 : port.dispose();
20
+ port = void 0;
21
+ };
22
+ onScopeDispose(dispose);
23
+ return { exposure: (input) => port == null ? void 0 : port.exposure(input), dispose };
24
+ }
25
+ export {
26
+ useBehaviorPort
27
+ };
package/es/index.mjs CHANGED
@@ -18,6 +18,7 @@ import { usePermission } from "./hooks/use-permission.mjs";
18
18
  import { buildRhythmCss, useCoreThemeApply } from "./hooks/use-theme-apply.mjs";
19
19
  import { useCoreViewportApply } from "./hooks/use-viewport-apply.mjs";
20
20
  import { useBridgeReport } from "./hooks/use-bridge-report.mjs";
21
+ import { useBehaviorPort } from "./hooks/use-behavior-port.mjs";
21
22
  import { APP_LAYOUT_APP_STORE_KEY, APP_LAYOUT_BRIDGE_KEY, APP_LAYOUT_USER_STORE_KEY, APP_PAGE_CONTENT_INSET, APP_PAGE_LIST_DETAIL_CONTEXT, APP_PAGE_NAV_BAR_ACTIVE, BODY_CONTENT_VIEWPORT_HEIGHT, BODY_CONTENT_VIEWPORT_INSET, BODY_CONTENT_VIEWPORT_RECT, CORE_BRIDGE_KEY, FORM_NEST_REGISTRY_KEY, FORM_VALIDATE_ERROR_KEYS, NEST_LAYOUT_SCALE_KEY, SCOPE_VIEWPORT_MAX_HEIGHT, TABS_MAIN_VISUAL_LEVEL, getModalShelfInjectionKey } from "./inject/key.mjs";
22
23
  import { createGuard } from "./router/guard/index.mjs";
23
24
  import { withGroupRedirect } from "./router/group-redirect.mjs";
@@ -55,6 +56,7 @@ import { default as default20 } from "./components/other/auto-refresh/AutoRefres
55
56
  import { default as default21 } from "./components/other/auto-refresh-group/AutoRefreshGroup.vue.mjs";
56
57
  import { default as default22 } from "./components/other/TriggerAutoImport.vue.mjs";
57
58
  import { BADGE_MASK_KINDS } from "./bridge/badge.mjs";
59
+ import { BEHAVIOR_DEFAULT_EVENTS, createBehaviorPort } from "./bridge/behavior.mjs";
58
60
  import { BridgeEventName, KNOWN_BRIDGE_EVENTS } from "./bridge/contracts/event.mjs";
59
61
  import { checkLogin } from "./router/guard/login.mjs";
60
62
  import { checkPermission } from "./router/guard/permission.mjs";
@@ -82,6 +84,7 @@ export {
82
84
  BADGE_HOST_ATTR,
83
85
  BADGE_KEY_ATTR,
84
86
  BADGE_MASK_KINDS,
87
+ BEHAVIOR_DEFAULT_EVENTS,
85
88
  BODY_CONTENT_VIEWPORT_HEIGHT,
86
89
  BODY_CONTENT_VIEWPORT_INSET,
87
90
  BODY_CONTENT_VIEWPORT_RECT,
@@ -122,6 +125,7 @@ export {
122
125
  checkPermissionRule,
123
126
  countAll,
124
127
  createAppStore,
128
+ createBehaviorPort,
125
129
  createCoreBridge,
126
130
  createGenerateRouteMetaRawTree,
127
131
  createGuard,
@@ -164,6 +168,7 @@ export {
164
168
  useActivated,
165
169
  useActivatedEvent,
166
170
  useActivatedExec,
171
+ useBehaviorPort,
167
172
  useBreakpoint,
168
173
  useBridgeReport,
169
174
  useChannelViewportHeight,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/forge-core",
3
- "version": "0.100.2-alpha.0",
3
+ "version": "0.100.3-alpha.0",
4
4
  "description": "Forge 配置化底座:桥接、共享契约、路由与状态工具及基础组件",
5
5
  "private": false,
6
6
  "main": "es/index.mjs",
@@ -228,5 +228,5 @@
228
228
  "engines": {
229
229
  "node": ">=18.0.0"
230
230
  },
231
- "gitHead": "c27ecedd6db04ecfb9de122b489e71f803c4d072"
231
+ "gitHead": "024ee62c04e058534a3e1a7154d14d4bf82d1d80"
232
232
  }
@@ -0,0 +1,43 @@
1
+ import { BridgeEventHook, BridgeEventName } from './contracts/event';
2
+ export interface BehaviorContext {
3
+ page?: {
4
+ path: string;
5
+ name?: string;
6
+ };
7
+ actor: {
8
+ kind: "anonymous" | "user";
9
+ id: string;
10
+ };
11
+ sessionId: string;
12
+ experiments?: Record<string, string>;
13
+ }
14
+ export interface BehaviorRecord {
15
+ kind: "action" | "exposure";
16
+ event: BridgeEventName | "exposure";
17
+ /** 默认集内经核查的事件为 user;应用经 events 追加的事件来源未核实。 */
18
+ origin: "user" | "unverified";
19
+ trackKey?: string;
20
+ source?: "standalone" | "group";
21
+ data: Record<string, string | number | boolean>;
22
+ context: BehaviorContext;
23
+ timestamp: number;
24
+ }
25
+ export interface BehaviorExposure {
26
+ experiment: string;
27
+ variant: string;
28
+ trackKey?: string;
29
+ }
30
+ export interface BehaviorPortOptions {
31
+ send: (record: BehaviorRecord) => void | Promise<void>;
32
+ context: () => BehaviorContext;
33
+ /** 覆盖默认事件集;加入 mixed/program 事件由应用负责来源判定。 */
34
+ events?: readonly BridgeEventName[];
35
+ }
36
+ export interface BehaviorPort {
37
+ exposure: (input: BehaviorExposure) => void;
38
+ dispose: () => void;
39
+ }
40
+ /** 当前交互接线核查结果,详见 docs/README-BehaviorPort.md。 */
41
+ export declare const BEHAVIOR_DEFAULT_EVENTS: readonly BridgeEventName[];
42
+ /** 只订阅传入实例,不安装全局资源;无 bridge 返回完全静默的句柄。 */
43
+ export declare function createBehaviorPort(bridge: Pick<BridgeEventHook, "onEvent"> | undefined, options: BehaviorPortOptions): BehaviorPort;
@@ -7,6 +7,11 @@ export interface BridgeEventGroupMeta {
7
7
  rowKey?: string | number;
8
8
  [key: string]: unknown;
9
9
  }
10
+ /** 组件发射始终含 source;可选声明兼容既有手工 bridge 生产者。 */
11
+ export interface BridgeEventActionMeta extends BridgeEventGroupMeta {
12
+ source?: "standalone" | "group";
13
+ trackKey?: string;
14
+ }
10
15
  /** 闭集事件契约。app/request 六事件仅预留,无自动采集源。 */
11
16
  export interface CoreBridgeEventRegistry {
12
17
  crash: {
@@ -53,7 +58,7 @@ export interface CoreBridgeEventRegistry {
53
58
  "confirm-open": {
54
59
  module: "component";
55
60
  submodule: "action-btn";
56
- data: BridgeEventGroupMeta & {
61
+ data: BridgeEventActionMeta & {
57
62
  type: string;
58
63
  title?: unknown;
59
64
  content?: unknown;
@@ -62,7 +67,7 @@ export interface CoreBridgeEventRegistry {
62
67
  "confirm-close": {
63
68
  module: "component";
64
69
  submodule: "action-btn";
65
- data: BridgeEventGroupMeta & {
70
+ data: BridgeEventActionMeta & {
66
71
  type: string;
67
72
  confirmed: boolean;
68
73
  };
@@ -70,7 +75,7 @@ export interface CoreBridgeEventRegistry {
70
75
  "action-click": {
71
76
  module: "component";
72
77
  submodule: "action-btn";
73
- data: BridgeEventGroupMeta & {
78
+ data: BridgeEventActionMeta & {
74
79
  type: string;
75
80
  };
76
81
  };
@@ -26,3 +26,4 @@ export type { CoreBridgePlugin, CoreBridgePluginBridgeSlice, CoreBridgePluginCon
26
26
  */
27
27
  export declare function createCoreBridge<UserInfo = unknown, LoginParams = unknown>(options: CoreBridgeInitOptions<UserInfo>): CoreBridge<UserInfo, LoginParams>;
28
28
  export * from './contracts/event';
29
+ export * from './behavior';
@@ -3,6 +3,7 @@ import { ActionBtnConfirmConfig } from '../display-contracts';
3
3
  export declare function useActionBtnReport(get: () => {
4
4
  type: string;
5
5
  groupMeta?: BridgeEventGroupMeta;
6
+ trackKey?: string;
6
7
  config?: ActionBtnConfirmConfig;
7
8
  }): {
8
9
  reportActionClick(): void;
@@ -1,6 +1,7 @@
1
+ /** 仅将定位交给 ActionBtn,不在父组件重复发射。ElButton 分支退出采集。 */
1
2
  export declare function useActionBtnGroupReport(): {
2
3
  withGroupMeta: (raw: Record<string, any>, key: string, index: number) => {
3
4
  groupMeta: any;
4
5
  };
5
- withNativeReport: (raw: Record<string, any>, key: string, index: number) => Record<string, any>;
6
+ withNativeProps: (raw: Record<string, any>) => Record<string, any>;
6
7
  };
@@ -39,13 +39,15 @@ export interface ActionBtnConfirmConfig {
39
39
  * - `loading` 被 Omit:有意的 ElButton 不兼容,唯一接管项——loading 由组件内部
40
40
  * 独占,对接异步 confirm / beforeOpen 的进行态(innerLoading),对外不可设置。
41
41
  * - `disabled` 原生透传,不改写不扩展。
42
- * - 增量:`confirmMode` / `confirmConfig` / `beforeOpen` / `badgeKey` / `groupMeta`。
42
+ * - 增量:`confirmMode` / `confirmConfig` / `beforeOpen` / `badgeKey` / `groupMeta` / `trackKey`。
43
43
  * - 泛型 `T`:由 `beforeOpen` 返回值反推,并透传给 `confirmConfig` 函数形态的
44
44
  * 入参;未传 `beforeOpen` 时默认 `T = void`,函数形态的 `data = undefined`。
45
45
  */
46
46
  export type ActionBtnProps<T = void> = Omit<ButtonProps, "loading"> & {
47
- /** 配置按钮定位;提供时才发 action-click。 */
47
+ /** 配置按钮定位;提供时 source 为 group,否则 standalone。 */
48
48
  groupMeta?: BridgeEventGroupMeta;
49
+ /** 应用显式提供的稳定业务动作标识,不放输入正文。 */
50
+ trackKey?: string;
49
51
  /** 确认交互形态,仅在 confirmConfig 存在时生效,默认 "popconfirm" */
50
52
  confirmMode?: ActionConfirmMode;
51
53
  /**
@@ -10,3 +10,4 @@ export * from './use-permission';
10
10
  export * from './use-theme-apply';
11
11
  export * from './use-viewport-apply';
12
12
  export * from './use-bridge-report';
13
+ export * from './use-behavior-port';
@@ -0,0 +1,3 @@
1
+ import { BehaviorPort, BehaviorPortOptions } from '../bridge/behavior';
2
+ /** 应用根 setup 接一次;立即接线,失活暂停,显式 dispose 永久停止。 */
3
+ export declare function useBehaviorPort(options: BehaviorPortOptions): BehaviorPort;