@mybricks/to-code-taro 1.0.5 → 1.0.6

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.
@@ -5403,7 +5403,7 @@
5403
5403
  },
5404
5404
  {
5405
5405
  "path": "src/core/utils/hooks.ts",
5406
- "content": "import { useState, useRef, useMemo } from 'react';\nimport { SUBJECT_SUBSCRIBE } from '../mybricks/constant';\nimport { createReactiveInputHandler } from '../mybricks/createReactiveInputHandler';\n\n/**\n * 深度代理,支持自动路径初始化和响应式更新(鸿蒙化处理方案)\n */\nexport function deepProxy(target: any, onSet?: () => void): any {\n if (target === null || typeof target !== 'object' || target.__isProxy) {\n return target;\n }\n\n return new Proxy(target, {\n get(obj, prop) {\n if (prop === '__isProxy') return true;\n if (prop === 'toJSON') return () => obj;\n\n let value = obj[prop];\n\n // 只有在访问不存在的对象属性时,才自动创建(实现类似 ensure 的效果)\n // 特意排除 MyBricks 内置的方法名,以便在生成代码中进行初始化判断\n const mybricksMethods = ['get', 'set', 'changed', 'reset', 'registerChange', 'call', 'apply', 'bind', 'push', 'pop'];\n if (value === undefined && typeof prop === 'string' && !mybricksMethods.includes(prop)) {\n value = obj[prop] = {};\n }\n\n if (typeof value === 'object' && value !== null && !value.__isProxy) {\n obj[prop] = deepProxy(value, onSet);\n }\n\n return obj[prop];\n },\n set(obj, prop, value) {\n const result = Reflect.set(obj, prop, value);\n if (onSet) onSet();\n return result;\n }\n });\n}\n\nexport function useModel(rawData: any) {\n const [, forceUpdate] = useState({});\n const dataRef = useRef(rawData || {});\n\n return useMemo(() => {\n return deepProxy(dataRef.current, () => forceUpdate({}));\n }, []);\n}\n\nexport function useBindInputs(scope: any, id: string, initialHandlers?: Record<string, any>) {\n const handlersRef = useRef<Record<string, any>>({ ...initialHandlers });\n\n // 同步最新的 initialHandlers\n if (initialHandlers) {\n Object.assign(handlersRef.current, initialHandlers);\n }\n\n return useMemo(() => {\n const proxy = new Proxy({}, {\n get: (_target, pin: string) => {\n return (arg: any, ...args: any[]) => {\n if (typeof arg === 'function') {\n // 组件注册回调\n handlersRef.current[pin] = arg;\n } else {\n // 逻辑流触发输入\n const handler = handlersRef.current[pin];\n\n if (typeof handler === 'function') {\n if (pin === '_setData') {\n return handler(arg, ...args);\n }\n // 构造 createReactiveInputHandler 需要的参数\n return createReactiveInputHandler({\n input: handler,\n value: arg,\n rels: {}, // 这里可以扩展 output 关联\n title: id\n });\n }\n }\n };\n }\n });\n\n // 将代理对象挂载到作用域,供外部 comRefs.current.id.pin() 调用\n scope[id] = proxy;\n return proxy;\n }, [scope, id]);\n}\n\nexport function useBindEvents(props: any) {\n return useMemo(() => {\n const _events: Record<string, any> = {};\n\n // 预处理已存在的事件\n Object.keys(props).forEach(key => {\n if (key.startsWith('on') && typeof props[key] === 'function') {\n const handler = props[key];\n const wrapped = (...args: any[]) => handler(...args);\n wrapped.getConnections = () => [{ id: 'default' }];\n _events[key] = wrapped;\n }\n });\n\n return new Proxy(_events, {\n get(target, key: string) {\n if (typeof key === 'string' && key.startsWith('on')) {\n if (target[key]) {\n return target[key];\n }\n // 对未连接的事件返回兜底函数\n const emptyFn = () => { };\n emptyFn.getConnections = () => [];\n return emptyFn;\n }\n return target[key];\n }\n });\n }, [props]);\n}\n"
5406
+ "content": "import { useState, useRef, useMemo } from 'react';\nimport { SUBJECT_SUBSCRIBE } from '../mybricks/constant';\nimport { createReactiveInputHandler } from '../mybricks/createReactiveInputHandler';\n\n/**\n * 深度代理,支持自动路径初始化和响应式更新(鸿蒙化处理方案)\n */\nexport function deepProxy(target: any, onSet?: () => void): any {\n if (target === null || typeof target !== 'object' || target.__isProxy) {\n return target;\n }\n\n return new Proxy(target, {\n get(obj, prop) {\n if (prop === '__isProxy') return true;\n if (prop === 'toJSON') return () => obj;\n\n let value = obj[prop];\n\n // 只代理已存在的对象属性,不自动创建空对象\n // 避免访问不存在的属性(如 disabled)时污染原始数据\n if (typeof value === 'object' && value !== null && !value.__isProxy) {\n obj[prop] = deepProxy(value, onSet);\n }\n\n return obj[prop];\n },\n set(obj, prop, value) {\n const result = Reflect.set(obj, prop, value);\n if (onSet) onSet();\n return result;\n }\n });\n}\n\nexport function useModel(rawData: any) {\n const [, forceUpdate] = useState({});\n const dataRef = useRef(rawData || {});\n\n return useMemo(() => {\n return deepProxy(dataRef.current, () => forceUpdate({}));\n }, []);\n}\n\nexport function useBindInputs(scope: any, id: string, initialHandlers?: Record<string, any>) {\n const handlersRef = useRef<Record<string, any>>({ ...initialHandlers });\n\n // 同步最新的 initialHandlers\n if (initialHandlers) {\n Object.assign(handlersRef.current, initialHandlers);\n }\n\n return useMemo(() => {\n const proxy = new Proxy({}, {\n get: (_target, pin: string) => {\n return (arg: any, ...args: any[]) => {\n if (typeof arg === 'function') {\n // 组件注册回调\n handlersRef.current[pin] = arg;\n } else {\n // 逻辑流触发输入\n const handler = handlersRef.current[pin];\n\n if (typeof handler === 'function') {\n if (pin === '_setData') {\n return handler(arg, ...args);\n }\n // 构造 createReactiveInputHandler 需要的参数\n return createReactiveInputHandler({\n input: handler,\n value: arg,\n rels: {}, // 这里可以扩展 output 关联\n title: id\n });\n }\n }\n };\n }\n });\n\n // 将代理对象挂载到作用域,供外部 comRefs.current.id.pin() 调用\n scope[id] = proxy;\n return proxy;\n }, [scope, id]);\n}\n\nexport function useBindEvents(props: any) {\n return useMemo(() => {\n const _events: Record<string, any> = {};\n\n // 预处理已存在的事件\n Object.keys(props).forEach(key => {\n if (key.startsWith('on') && typeof props[key] === 'function') {\n const handler = props[key];\n const wrapped = (...args: any[]) => handler(...args);\n wrapped.getConnections = () => [{ id: 'default' }];\n _events[key] = wrapped;\n }\n });\n\n return new Proxy(_events, {\n get(target, key: string) {\n if (typeof key === 'string' && key.startsWith('on')) {\n if (target[key]) {\n return target[key];\n }\n // 对未连接的事件返回兜底函数\n const emptyFn = () => { };\n emptyFn.getConnections = () => [];\n return emptyFn;\n }\n return target[key];\n }\n });\n }, [props]);\n}\n"
5407
5407
  },
5408
5408
  {
5409
5409
  "path": "src/core/utils/index.ts",
@@ -5403,7 +5403,7 @@
5403
5403
  },
5404
5404
  {
5405
5405
  "path": "src/core/utils/hooks.ts",
5406
- "content": "import { useState, useRef, useMemo } from 'react';\nimport { SUBJECT_SUBSCRIBE } from '../mybricks/constant';\nimport { createReactiveInputHandler } from '../mybricks/createReactiveInputHandler';\n\n/**\n * 深度代理,支持自动路径初始化和响应式更新(鸿蒙化处理方案)\n */\nexport function deepProxy(target: any, onSet?: () => void): any {\n if (target === null || typeof target !== 'object' || target.__isProxy) {\n return target;\n }\n\n return new Proxy(target, {\n get(obj, prop) {\n if (prop === '__isProxy') return true;\n if (prop === 'toJSON') return () => obj;\n\n let value = obj[prop];\n\n // 只有在访问不存在的对象属性时,才自动创建(实现类似 ensure 的效果)\n // 特意排除 MyBricks 内置的方法名,以便在生成代码中进行初始化判断\n const mybricksMethods = ['get', 'set', 'changed', 'reset', 'registerChange', 'call', 'apply', 'bind', 'push', 'pop'];\n if (value === undefined && typeof prop === 'string' && !mybricksMethods.includes(prop)) {\n value = obj[prop] = {};\n }\n\n if (typeof value === 'object' && value !== null && !value.__isProxy) {\n obj[prop] = deepProxy(value, onSet);\n }\n\n return obj[prop];\n },\n set(obj, prop, value) {\n const result = Reflect.set(obj, prop, value);\n if (onSet) onSet();\n return result;\n }\n });\n}\n\nexport function useModel(rawData: any) {\n const [, forceUpdate] = useState({});\n const dataRef = useRef(rawData || {});\n\n return useMemo(() => {\n return deepProxy(dataRef.current, () => forceUpdate({}));\n }, []);\n}\n\nexport function useBindInputs(scope: any, id: string, initialHandlers?: Record<string, any>) {\n const handlersRef = useRef<Record<string, any>>({ ...initialHandlers });\n\n // 同步最新的 initialHandlers\n if (initialHandlers) {\n Object.assign(handlersRef.current, initialHandlers);\n }\n\n return useMemo(() => {\n const proxy = new Proxy({}, {\n get: (_target, pin: string) => {\n return (arg: any, ...args: any[]) => {\n if (typeof arg === 'function') {\n // 组件注册回调\n handlersRef.current[pin] = arg;\n } else {\n // 逻辑流触发输入\n const handler = handlersRef.current[pin];\n\n if (typeof handler === 'function') {\n if (pin === '_setData') {\n return handler(arg, ...args);\n }\n // 构造 createReactiveInputHandler 需要的参数\n return createReactiveInputHandler({\n input: handler,\n value: arg,\n rels: {}, // 这里可以扩展 output 关联\n title: id\n });\n }\n }\n };\n }\n });\n\n // 将代理对象挂载到作用域,供外部 comRefs.current.id.pin() 调用\n scope[id] = proxy;\n return proxy;\n }, [scope, id]);\n}\n\nexport function useBindEvents(props: any) {\n return useMemo(() => {\n const _events: Record<string, any> = {};\n\n // 预处理已存在的事件\n Object.keys(props).forEach(key => {\n if (key.startsWith('on') && typeof props[key] === 'function') {\n const handler = props[key];\n const wrapped = (...args: any[]) => handler(...args);\n wrapped.getConnections = () => [{ id: 'default' }];\n _events[key] = wrapped;\n }\n });\n\n return new Proxy(_events, {\n get(target, key: string) {\n if (typeof key === 'string' && key.startsWith('on')) {\n if (target[key]) {\n return target[key];\n }\n // 对未连接的事件返回兜底函数\n const emptyFn = () => { };\n emptyFn.getConnections = () => [];\n return emptyFn;\n }\n return target[key];\n }\n });\n }, [props]);\n}\n"
5406
+ "content": "import { useState, useRef, useMemo } from 'react';\nimport { SUBJECT_SUBSCRIBE } from '../mybricks/constant';\nimport { createReactiveInputHandler } from '../mybricks/createReactiveInputHandler';\n\n/**\n * 深度代理,支持自动路径初始化和响应式更新(鸿蒙化处理方案)\n */\nexport function deepProxy(target: any, onSet?: () => void): any {\n if (target === null || typeof target !== 'object' || target.__isProxy) {\n return target;\n }\n\n return new Proxy(target, {\n get(obj, prop) {\n if (prop === '__isProxy') return true;\n if (prop === 'toJSON') return () => obj;\n\n let value = obj[prop];\n\n // 只代理已存在的对象属性,不自动创建空对象\n // 避免访问不存在的属性(如 disabled)时污染原始数据\n if (typeof value === 'object' && value !== null && !value.__isProxy) {\n obj[prop] = deepProxy(value, onSet);\n }\n\n return obj[prop];\n },\n set(obj, prop, value) {\n const result = Reflect.set(obj, prop, value);\n if (onSet) onSet();\n return result;\n }\n });\n}\n\nexport function useModel(rawData: any) {\n const [, forceUpdate] = useState({});\n const dataRef = useRef(rawData || {});\n\n return useMemo(() => {\n return deepProxy(dataRef.current, () => forceUpdate({}));\n }, []);\n}\n\nexport function useBindInputs(scope: any, id: string, initialHandlers?: Record<string, any>) {\n const handlersRef = useRef<Record<string, any>>({ ...initialHandlers });\n\n // 同步最新的 initialHandlers\n if (initialHandlers) {\n Object.assign(handlersRef.current, initialHandlers);\n }\n\n return useMemo(() => {\n const proxy = new Proxy({}, {\n get: (_target, pin: string) => {\n return (arg: any, ...args: any[]) => {\n if (typeof arg === 'function') {\n // 组件注册回调\n handlersRef.current[pin] = arg;\n } else {\n // 逻辑流触发输入\n const handler = handlersRef.current[pin];\n\n if (typeof handler === 'function') {\n if (pin === '_setData') {\n return handler(arg, ...args);\n }\n // 构造 createReactiveInputHandler 需要的参数\n return createReactiveInputHandler({\n input: handler,\n value: arg,\n rels: {}, // 这里可以扩展 output 关联\n title: id\n });\n }\n }\n };\n }\n });\n\n // 将代理对象挂载到作用域,供外部 comRefs.current.id.pin() 调用\n scope[id] = proxy;\n return proxy;\n }, [scope, id]);\n}\n\nexport function useBindEvents(props: any) {\n return useMemo(() => {\n const _events: Record<string, any> = {};\n\n // 预处理已存在的事件\n Object.keys(props).forEach(key => {\n if (key.startsWith('on') && typeof props[key] === 'function') {\n const handler = props[key];\n const wrapped = (...args: any[]) => handler(...args);\n wrapped.getConnections = () => [{ id: 'default' }];\n _events[key] = wrapped;\n }\n });\n\n return new Proxy(_events, {\n get(target, key: string) {\n if (typeof key === 'string' && key.startsWith('on')) {\n if (target[key]) {\n return target[key];\n }\n // 对未连接的事件返回兜底函数\n const emptyFn = () => { };\n emptyFn.getConnections = () => [];\n return emptyFn;\n }\n return target[key];\n }\n });\n }, [props]);\n}\n"
5407
5407
  },
5408
5408
  {
5409
5409
  "path": "src/core/utils/index.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mybricks/to-code-taro",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "To code for Taro",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",