vue 2.6.13 → 2.7.0-alpha.2

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 (262) hide show
  1. package/README.md +17 -295
  2. package/compiler-sfc/index.d.ts +1 -0
  3. package/compiler-sfc/index.js +1 -0
  4. package/compiler-sfc/index.mjs +1 -0
  5. package/compiler-sfc/package.json +5 -0
  6. package/dist/vue.common.dev.js +11481 -11946
  7. package/dist/vue.common.prod.js +8 -3
  8. package/dist/vue.esm.browser.js +11321 -12011
  9. package/dist/vue.esm.browser.min.js +8 -3
  10. package/dist/vue.esm.js +11476 -11984
  11. package/dist/vue.js +11484 -11949
  12. package/dist/vue.min.js +8 -3
  13. package/dist/vue.runtime.common.dev.js +8427 -8421
  14. package/dist/vue.runtime.common.prod.js +8 -3
  15. package/dist/vue.runtime.esm.js +8436 -8454
  16. package/dist/vue.runtime.js +8430 -8424
  17. package/dist/vue.runtime.min.js +8 -3
  18. package/package.json +88 -111
  19. package/packages/compiler-sfc/dist/compiler-sfc.js +7 -0
  20. package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
  21. package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
  22. package/packages/compiler-sfc/package.json +30 -0
  23. package/src/compiler/{codeframe.js → codeframe.ts} +9 -7
  24. package/src/compiler/codegen/{events.js → events.ts} +21 -41
  25. package/src/compiler/codegen/{index.js → index.ts} +146 -136
  26. package/src/compiler/{create-compiler.js → create-compiler.ts} +26 -18
  27. package/src/compiler/directives/bind.ts +9 -0
  28. package/src/compiler/directives/{index.js → index.ts} +0 -2
  29. package/src/compiler/directives/{model.js → model.ts} +15 -18
  30. package/src/compiler/directives/{on.js → on.ts} +3 -4
  31. package/src/compiler/{error-detector.js → error-detector.ts} +61 -31
  32. package/src/compiler/{helpers.js → helpers.ts} +73 -61
  33. package/src/compiler/{index.js → index.ts} +2 -3
  34. package/src/compiler/{optimizer.js → optimizer.ts} +30 -23
  35. package/src/compiler/parser/{entity-decoder.js → entity-decoder.ts} +1 -3
  36. package/src/compiler/parser/{filter-parser.js → filter-parser.ts} +43 -24
  37. package/src/compiler/parser/{html-parser.js → html-parser.ts} +50 -29
  38. package/src/compiler/parser/{index.js → index.ts} +190 -172
  39. package/src/compiler/parser/{text-parser.js → text-parser.ts} +8 -9
  40. package/src/compiler/{to-function.js → to-function.ts} +27 -22
  41. package/src/core/components/{index.js → index.ts} +0 -0
  42. package/src/core/components/{keep-alive.js → keep-alive.ts} +42 -30
  43. package/src/core/{config.js → config.ts} +28 -30
  44. package/src/core/global-api/{assets.js → assets.ts} +8 -7
  45. package/src/core/global-api/{extend.js → extend.ts} +10 -13
  46. package/src/core/global-api/{index.js → index.ts} +4 -5
  47. package/src/core/global-api/{mixin.js → mixin.ts} +2 -3
  48. package/src/core/global-api/use.ts +23 -0
  49. package/src/core/{index.js → index.ts} +1 -1
  50. package/src/core/instance/{events.js → events.ts} +41 -24
  51. package/src/core/instance/{index.js → index.ts} +9 -5
  52. package/src/core/instance/{init.js → init.ts} +26 -15
  53. package/src/core/instance/inject.ts +72 -0
  54. package/src/core/instance/{lifecycle.js → lifecycle.ts} +86 -44
  55. package/src/core/instance/{proxy.js → proxy.ts} +29 -24
  56. package/src/core/instance/render-helpers/{bind-dynamic-keys.js → bind-dynamic-keys.ts} +6 -5
  57. package/src/core/instance/render-helpers/{bind-object-listeners.js → bind-object-listeners.ts} +4 -8
  58. package/src/core/instance/render-helpers/{bind-object-props.js → bind-object-props.ts} +12 -17
  59. package/src/core/instance/render-helpers/{check-keycodes.js → check-keycodes.ts} +5 -7
  60. package/src/core/instance/render-helpers/{index.js → index.ts} +1 -3
  61. package/src/core/instance/render-helpers/{render-list.js → render-list.ts} +12 -13
  62. package/src/core/instance/render-helpers/{render-slot.js → render-slot.ts} +10 -11
  63. package/src/core/instance/render-helpers/{render-static.js → render-static.ts} +7 -10
  64. package/src/core/instance/render-helpers/{resolve-filter.js → resolve-filter.ts} +1 -3
  65. package/src/core/instance/render-helpers/{resolve-scoped-slots.js → resolve-scoped-slots.ts} +11 -8
  66. package/src/core/instance/render-helpers/{resolve-slots.js → resolve-slots.ts} +12 -11
  67. package/src/core/instance/{render.js → render.ts} +66 -29
  68. package/src/core/instance/{state.js → state.ts} +100 -83
  69. package/src/core/observer/{array.js → array.ts} +11 -2
  70. package/src/core/observer/{dep.js → dep.ts} +37 -15
  71. package/src/core/observer/{index.js → index.ts} +137 -71
  72. package/src/core/observer/{scheduler.js → scheduler.ts} +42 -43
  73. package/src/core/observer/{traverse.js → traverse.ts} +10 -7
  74. package/src/core/observer/{watcher.js → watcher.ts} +88 -60
  75. package/src/core/util/{debug.js → debug.ts} +38 -34
  76. package/src/core/util/{env.js → env.ts} +27 -30
  77. package/src/core/util/{error.js → error.ts} +12 -14
  78. package/src/core/util/{index.js → index.ts} +0 -2
  79. package/src/core/util/{lang.js → lang.ts} +6 -7
  80. package/src/core/util/{next-tick.js → next-tick.ts} +16 -10
  81. package/src/core/util/{options.js → options.ts} +119 -114
  82. package/src/core/util/{perf.js → perf.ts} +5 -1
  83. package/src/core/util/{props.js → props.ts} +54 -50
  84. package/src/core/vdom/{create-component.js → create-component.ts} +51 -50
  85. package/src/core/vdom/{create-element.js → create-element.ts} +49 -43
  86. package/src/core/vdom/{create-functional-component.js → create-functional-component.ts} +52 -27
  87. package/src/core/vdom/helpers/{extract-props.js → extract-props.ts} +18 -18
  88. package/src/core/vdom/helpers/{get-first-component-child.js → get-first-component-child.ts} +6 -5
  89. package/src/core/vdom/helpers/{index.js → index.ts} +0 -2
  90. package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
  91. package/src/core/vdom/helpers/{merge-hook.js → merge-hook.ts} +7 -5
  92. package/src/core/vdom/helpers/{normalize-children.js → normalize-children.ts} +26 -16
  93. package/src/core/vdom/helpers/{normalize-scoped-slots.js → normalize-scoped-slots.ts} +23 -17
  94. package/src/core/vdom/helpers/{resolve-async-component.js → resolve-async-component.ts} +29 -37
  95. package/src/core/vdom/helpers/update-listeners.ts +101 -0
  96. package/src/core/vdom/modules/{directives.js → directives.ts} +20 -14
  97. package/src/core/vdom/modules/index.ts +4 -0
  98. package/src/core/vdom/modules/template-ref.ts +96 -0
  99. package/src/core/vdom/{patch.js → patch.ts} +239 -138
  100. package/src/core/vdom/{vnode.js → vnode.ts} +36 -31
  101. package/src/global.d.ts +15 -0
  102. package/src/platforms/web/compiler/directives/html.ts +8 -0
  103. package/src/platforms/web/compiler/directives/{index.js → index.ts} +0 -0
  104. package/src/platforms/web/compiler/directives/{model.js → model.ts} +47 -41
  105. package/src/platforms/web/compiler/directives/{text.js → text.ts} +2 -3
  106. package/src/platforms/web/compiler/{index.js → index.ts} +0 -2
  107. package/src/platforms/web/compiler/modules/{class.js → class.ts} +10 -15
  108. package/src/platforms/web/compiler/modules/{index.js → index.ts} +1 -5
  109. package/src/platforms/web/compiler/modules/{model.js → model.ts} +6 -11
  110. package/src/platforms/web/compiler/modules/{style.js → style.ts} +9 -14
  111. package/src/platforms/web/compiler/{options.js → options.ts} +1 -2
  112. package/src/platforms/web/compiler/{util.js → util.ts} +5 -7
  113. package/src/platforms/web/entry-compiler-sfc.ts +1 -0
  114. package/src/platforms/web/{entry-compiler.js → entry-compiler.ts} +1 -3
  115. package/src/platforms/web/{entry-runtime.js → entry-runtime-esm.ts} +2 -2
  116. package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
  117. package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
  118. package/src/platforms/web/entry-runtime.ts +7 -0
  119. package/src/platforms/web/runtime/{class-util.js → class-util.ts} +2 -4
  120. package/src/platforms/web/runtime/components/{index.js → index.ts} +0 -0
  121. package/src/platforms/web/runtime/components/{transition-group.js → transition-group.ts} +59 -46
  122. package/src/platforms/web/runtime/components/{transition.js → transition.ts} +43 -36
  123. package/src/platforms/web/runtime/directives/{index.js → index.ts} +0 -0
  124. package/src/platforms/web/runtime/directives/{model.js → model.ts} +22 -21
  125. package/src/platforms/web/runtime/directives/{show.js → show.ts} +11 -10
  126. package/src/platforms/web/runtime/{index.js → index.ts} +9 -10
  127. package/src/platforms/web/runtime/modules/{attrs.js → attrs.ts} +12 -16
  128. package/src/platforms/web/runtime/modules/{class.js → class.ts} +7 -18
  129. package/src/platforms/web/runtime/modules/{dom-props.js → dom-props.ts} +24 -17
  130. package/src/platforms/web/runtime/modules/{events.js → events.ts} +22 -15
  131. package/src/platforms/web/runtime/modules/{index.js → index.ts} +1 -8
  132. package/src/platforms/web/runtime/modules/{style.js → style.ts} +24 -13
  133. package/src/platforms/web/runtime/modules/{transition.js → transition.ts} +61 -63
  134. package/src/platforms/web/runtime/node-ops.ts +66 -0
  135. package/src/platforms/web/runtime/{patch.js → patch.ts} +0 -2
  136. package/src/platforms/web/runtime/{transition-util.js → transition-util.ts} +63 -38
  137. package/src/platforms/web/{entry-runtime-with-compiler.js → runtime-with-compiler.ts} +28 -19
  138. package/src/platforms/web/util/{attrs.js → attrs.ts} +18 -14
  139. package/src/platforms/web/util/{class.js → class.ts} +23 -21
  140. package/src/platforms/web/util/{compat.js → compat.ts} +4 -4
  141. package/src/platforms/web/util/{element.js → element.ts} +21 -22
  142. package/src/platforms/web/util/{index.js → index.ts} +2 -6
  143. package/src/platforms/web/util/{style.js → style.ts} +12 -12
  144. package/src/sfc/{parser.js → parser.ts} +18 -15
  145. package/src/shared/{constants.js → constants.ts} +2 -6
  146. package/src/shared/{util.js → util.ts} +78 -55
  147. package/src/types/compiler.ts +224 -0
  148. package/src/types/component.ts +209 -0
  149. package/src/types/global-api.ts +37 -0
  150. package/src/types/modules.d.ts +15 -0
  151. package/src/types/options.ts +120 -0
  152. package/src/types/ssr.ts +27 -0
  153. package/src/types/utils.ts +3 -0
  154. package/src/types/vnode.ts +127 -0
  155. package/src/v3/apiInject.ts +66 -0
  156. package/src/v3/apiLifecycle.ts +53 -0
  157. package/src/v3/apiSetup.ts +161 -0
  158. package/src/v3/apiWatch.ts +355 -0
  159. package/src/v3/currentInstance.ts +23 -0
  160. package/src/v3/debug.ts +21 -0
  161. package/src/v3/h.ts +18 -0
  162. package/src/v3/index.ts +77 -0
  163. package/src/v3/reactivity/computed.ts +100 -0
  164. package/src/v3/reactivity/effect.ts +20 -0
  165. package/src/v3/reactivity/effectScope.ts +134 -0
  166. package/src/v3/reactivity/operations.ts +14 -0
  167. package/src/v3/reactivity/reactive.ts +123 -0
  168. package/src/v3/reactivity/readonly.ts +121 -0
  169. package/src/v3/reactivity/ref.ts +249 -0
  170. package/types/index.d.ts +10 -13
  171. package/types/options.d.ts +265 -132
  172. package/types/plugin.d.ts +4 -4
  173. package/types/umd.d.ts +47 -27
  174. package/types/v3-generated.d.ts +389 -0
  175. package/types/v3.d.ts +16 -0
  176. package/types/vnode.d.ts +70 -57
  177. package/types/vue.d.ts +292 -88
  178. package/dist/README.md +0 -122
  179. package/src/compiler/directives/bind.js +0 -11
  180. package/src/core/global-api/use.js +0 -23
  181. package/src/core/instance/inject.js +0 -73
  182. package/src/core/vdom/helpers/is-async-placeholder.js +0 -5
  183. package/src/core/vdom/helpers/update-listeners.js +0 -95
  184. package/src/core/vdom/modules/index.js +0 -7
  185. package/src/core/vdom/modules/ref.js +0 -45
  186. package/src/platforms/web/compiler/directives/html.js +0 -9
  187. package/src/platforms/web/entry-server-basic-renderer.js +0 -13
  188. package/src/platforms/web/entry-server-renderer.js +0 -27
  189. package/src/platforms/web/runtime/node-ops.js +0 -59
  190. package/src/platforms/web/server/compiler.js +0 -11
  191. package/src/platforms/web/server/directives/index.js +0 -7
  192. package/src/platforms/web/server/directives/model.js +0 -44
  193. package/src/platforms/web/server/directives/show.js +0 -12
  194. package/src/platforms/web/server/modules/attrs.js +0 -67
  195. package/src/platforms/web/server/modules/class.js +0 -11
  196. package/src/platforms/web/server/modules/dom-props.js +0 -50
  197. package/src/platforms/web/server/modules/index.js +0 -11
  198. package/src/platforms/web/server/modules/style.js +0 -41
  199. package/src/platforms/web/server/util.js +0 -101
  200. package/src/platforms/weex/compiler/directives/index.js +0 -5
  201. package/src/platforms/weex/compiler/directives/model.js +0 -33
  202. package/src/platforms/weex/compiler/index.js +0 -52
  203. package/src/platforms/weex/compiler/modules/append.js +0 -27
  204. package/src/platforms/weex/compiler/modules/class.js +0 -74
  205. package/src/platforms/weex/compiler/modules/index.js +0 -13
  206. package/src/platforms/weex/compiler/modules/props.js +0 -37
  207. package/src/platforms/weex/compiler/modules/recycle-list/component-root.js +0 -13
  208. package/src/platforms/weex/compiler/modules/recycle-list/component.js +0 -16
  209. package/src/platforms/weex/compiler/modules/recycle-list/index.js +0 -60
  210. package/src/platforms/weex/compiler/modules/recycle-list/recycle-list.js +0 -50
  211. package/src/platforms/weex/compiler/modules/recycle-list/text.js +0 -23
  212. package/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +0 -21
  213. package/src/platforms/weex/compiler/modules/recycle-list/v-for.js +0 -33
  214. package/src/platforms/weex/compiler/modules/recycle-list/v-if.js +0 -63
  215. package/src/platforms/weex/compiler/modules/recycle-list/v-on.js +0 -25
  216. package/src/platforms/weex/compiler/modules/recycle-list/v-once.js +0 -19
  217. package/src/platforms/weex/compiler/modules/style.js +0 -87
  218. package/src/platforms/weex/entry-compiler.js +0 -2
  219. package/src/platforms/weex/entry-framework.js +0 -187
  220. package/src/platforms/weex/entry-runtime-factory.js +0 -6
  221. package/src/platforms/weex/runtime/components/index.js +0 -9
  222. package/src/platforms/weex/runtime/components/richtext.js +0 -82
  223. package/src/platforms/weex/runtime/components/transition-group.js +0 -148
  224. package/src/platforms/weex/runtime/components/transition.js +0 -9
  225. package/src/platforms/weex/runtime/directives/index.js +0 -2
  226. package/src/platforms/weex/runtime/index.js +0 -42
  227. package/src/platforms/weex/runtime/modules/attrs.js +0 -44
  228. package/src/platforms/weex/runtime/modules/class.js +0 -76
  229. package/src/platforms/weex/runtime/modules/events.js +0 -54
  230. package/src/platforms/weex/runtime/modules/index.js +0 -13
  231. package/src/platforms/weex/runtime/modules/style.js +0 -84
  232. package/src/platforms/weex/runtime/modules/transition.js +0 -270
  233. package/src/platforms/weex/runtime/node-ops.js +0 -91
  234. package/src/platforms/weex/runtime/patch.js +0 -16
  235. package/src/platforms/weex/runtime/recycle-list/render-component-template.js +0 -34
  236. package/src/platforms/weex/runtime/recycle-list/virtual-component.js +0 -136
  237. package/src/platforms/weex/runtime/text-node.js +0 -9
  238. package/src/platforms/weex/util/element.js +0 -52
  239. package/src/platforms/weex/util/index.js +0 -40
  240. package/src/platforms/weex/util/parser.js +0 -60
  241. package/src/server/bundle-renderer/create-bundle-renderer.js +0 -151
  242. package/src/server/bundle-renderer/create-bundle-runner.js +0 -150
  243. package/src/server/bundle-renderer/source-map-support.js +0 -45
  244. package/src/server/create-basic-renderer.js +0 -37
  245. package/src/server/create-renderer.js +0 -152
  246. package/src/server/optimizing-compiler/codegen.js +0 -264
  247. package/src/server/optimizing-compiler/index.js +0 -20
  248. package/src/server/optimizing-compiler/modules.js +0 -124
  249. package/src/server/optimizing-compiler/optimizer.js +0 -141
  250. package/src/server/optimizing-compiler/runtime-helpers.js +0 -150
  251. package/src/server/render-context.js +0 -130
  252. package/src/server/render-stream.js +0 -95
  253. package/src/server/render.js +0 -437
  254. package/src/server/template-renderer/create-async-file-mapper.js +0 -57
  255. package/src/server/template-renderer/index.js +0 -277
  256. package/src/server/template-renderer/parse-template.js +0 -42
  257. package/src/server/template-renderer/template-stream.js +0 -82
  258. package/src/server/util.js +0 -18
  259. package/src/server/webpack-plugin/client.js +0 -65
  260. package/src/server/webpack-plugin/server.js +0 -66
  261. package/src/server/webpack-plugin/util.js +0 -34
  262. package/src/server/write.js +0 -50
@@ -0,0 +1,249 @@
1
+ import { defineReactive } from 'core/observer/index'
2
+ import {
3
+ isReactive,
4
+ ReactiveFlags,
5
+ type ShallowReactiveMarker
6
+ } from './reactive'
7
+ import type { IfAny } from 'types/utils'
8
+ import Dep from 'core/observer/dep'
9
+ import { warn, isArray, def } from 'core/util'
10
+ import { TrackOpTypes, TriggerOpTypes } from './operations'
11
+
12
+ declare const RefSymbol: unique symbol
13
+ export declare const RawSymbol: unique symbol
14
+
15
+ /**
16
+ * @internal
17
+ */
18
+ export const RefFlag = `__v_isRef`
19
+
20
+ export interface Ref<T = any> {
21
+ value: T
22
+ /**
23
+ * Type differentiator only.
24
+ * We need this to be in public d.ts but don't want it to show up in IDE
25
+ * autocomplete, so we use a private Symbol instead.
26
+ */
27
+ [RefSymbol]: true
28
+ /**
29
+ * @internal
30
+ */
31
+ dep?: Dep
32
+ /**
33
+ * @internal
34
+ */
35
+ [RefFlag]: true
36
+ }
37
+
38
+ export function isRef<T>(r: Ref<T> | unknown): r is Ref<T>
39
+ export function isRef(r: any): r is Ref {
40
+ return !!(r && (r as Ref).__v_isRef === true)
41
+ }
42
+
43
+ export function ref<T extends object>(
44
+ value: T
45
+ ): [T] extends [Ref] ? T : Ref<UnwrapRef<T>>
46
+ export function ref<T>(value: T): Ref<UnwrapRef<T>>
47
+ export function ref<T = any>(): Ref<T | undefined>
48
+ export function ref(value?: unknown) {
49
+ return createRef(value, false)
50
+ }
51
+
52
+ declare const ShallowRefMarker: unique symbol
53
+
54
+ export type ShallowRef<T = any> = Ref<T> & { [ShallowRefMarker]?: true }
55
+
56
+ export function shallowRef<T extends object>(
57
+ value: T
58
+ ): T extends Ref ? T : ShallowRef<T>
59
+ export function shallowRef<T>(value: T): ShallowRef<T>
60
+ export function shallowRef<T = any>(): ShallowRef<T | undefined>
61
+ export function shallowRef(value?: unknown) {
62
+ return createRef(value, true)
63
+ }
64
+
65
+ function createRef(rawValue: unknown, shallow: boolean) {
66
+ if (isRef(rawValue)) {
67
+ return rawValue
68
+ }
69
+ const ref: any = {}
70
+ def(ref, RefFlag, true)
71
+ def(ref, ReactiveFlags.IS_SHALLOW, true)
72
+ ref.dep = defineReactive(ref, 'value', rawValue, null, shallow)
73
+ return ref
74
+ }
75
+
76
+ export function triggerRef(ref: Ref) {
77
+ if (__DEV__ && !ref.dep) {
78
+ warn(`received object is not a triggerable ref.`)
79
+ }
80
+ if (__DEV__) {
81
+ ref.dep &&
82
+ ref.dep.notify({
83
+ type: TriggerOpTypes.SET,
84
+ target: ref,
85
+ key: 'value'
86
+ })
87
+ } else {
88
+ ref.dep && ref.dep.notify()
89
+ }
90
+ }
91
+
92
+ export function unref<T>(ref: T | Ref<T>): T {
93
+ return isRef(ref) ? (ref.value as any) : ref
94
+ }
95
+
96
+ export type CustomRefFactory<T> = (
97
+ track: () => void,
98
+ trigger: () => void
99
+ ) => {
100
+ get: () => T
101
+ set: (value: T) => void
102
+ }
103
+
104
+ export function customRef<T>(factory: CustomRefFactory<T>): Ref<T> {
105
+ const dep = new Dep()
106
+ const { get, set } = factory(
107
+ () => {
108
+ if (__DEV__) {
109
+ dep.depend({
110
+ target: ref,
111
+ type: TrackOpTypes.GET,
112
+ key: 'value'
113
+ })
114
+ } else {
115
+ dep.depend()
116
+ }
117
+ },
118
+ () => {
119
+ if (__DEV__) {
120
+ dep.notify({
121
+ target: ref,
122
+ type: TriggerOpTypes.SET,
123
+ key: 'value'
124
+ })
125
+ } else {
126
+ dep.notify()
127
+ }
128
+ }
129
+ )
130
+ const ref = {
131
+ get value() {
132
+ return get()
133
+ },
134
+ set value(newVal) {
135
+ set(newVal)
136
+ }
137
+ } as any
138
+ def(ref, RefFlag, true)
139
+ return ref
140
+ }
141
+
142
+ export type ToRefs<T = any> = {
143
+ [K in keyof T]: ToRef<T[K]>
144
+ }
145
+
146
+ export function toRefs<T extends object>(object: T): ToRefs<T> {
147
+ if (__DEV__ && !isReactive(object)) {
148
+ warn(`toRefs() expects a reactive object but received a plain one.`)
149
+ }
150
+ const ret: any = isArray(object) ? new Array(object.length) : {}
151
+ for (const key in object) {
152
+ ret[key] = toRef(object, key)
153
+ }
154
+ return ret
155
+ }
156
+
157
+ export type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>
158
+
159
+ export function toRef<T extends object, K extends keyof T>(
160
+ object: T,
161
+ key: K
162
+ ): ToRef<T[K]>
163
+
164
+ export function toRef<T extends object, K extends keyof T>(
165
+ object: T,
166
+ key: K,
167
+ defaultValue: T[K]
168
+ ): ToRef<Exclude<T[K], undefined>>
169
+
170
+ export function toRef<T extends object, K extends keyof T>(
171
+ object: T,
172
+ key: K,
173
+ defaultValue?: T[K]
174
+ ): ToRef<T[K]> {
175
+ const val = object[key]
176
+ if (isRef(val)) {
177
+ return val as any
178
+ }
179
+ const ref = {
180
+ get value() {
181
+ const val = object[key]
182
+ return val === undefined ? (defaultValue as T[K]) : val
183
+ },
184
+ set value(newVal) {
185
+ object[key] = newVal
186
+ }
187
+ } as any
188
+ def(ref, RefFlag, true)
189
+ return ref
190
+ }
191
+
192
+ /**
193
+ * This is a special exported interface for other packages to declare
194
+ * additional types that should bail out for ref unwrapping. For example
195
+ * \@vue/runtime-dom can declare it like so in its d.ts:
196
+ *
197
+ * ``` ts
198
+ * declare module 'vue' {
199
+ * export interface RefUnwrapBailTypes {
200
+ * runtimeDOMBailTypes: Node | Window
201
+ * }
202
+ * }
203
+ * ```
204
+ *
205
+ * Note that api-extractor somehow refuses to include `declare module`
206
+ * augmentations in its generated d.ts, so we have to manually append them
207
+ * to the final generated d.ts in our build process.
208
+ */
209
+ export interface RefUnwrapBailTypes {
210
+ runtimeDOMBailTypes: Node | Window
211
+ }
212
+
213
+ export type ShallowUnwrapRef<T> = {
214
+ [K in keyof T]: T[K] extends Ref<infer V>
215
+ ? V
216
+ : // if `V` is `unknown` that means it does not extend `Ref` and is undefined
217
+ T[K] extends Ref<infer V> | undefined
218
+ ? unknown extends V
219
+ ? undefined
220
+ : V | undefined
221
+ : T[K]
222
+ }
223
+
224
+ export type UnwrapRef<T> = T extends ShallowRef<infer V>
225
+ ? V
226
+ : T extends Ref<infer V>
227
+ ? UnwrapRefSimple<V>
228
+ : UnwrapRefSimple<T>
229
+
230
+ type BaseTypes = string | number | boolean
231
+ type CollectionTypes = IterableCollections | WeakCollections
232
+ type IterableCollections = Map<any, any> | Set<any>
233
+ type WeakCollections = WeakMap<any, any> | WeakSet<any>
234
+
235
+ export type UnwrapRefSimple<T> = T extends
236
+ | Function
237
+ | CollectionTypes
238
+ | BaseTypes
239
+ | Ref
240
+ | RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
241
+ | { [RawSymbol]?: true }
242
+ ? T
243
+ : T extends Array<any>
244
+ ? { [K in keyof T]: UnwrapRefSimple<T[K]> }
245
+ : T extends object & { [ShallowReactiveMarker]?: never }
246
+ ? {
247
+ [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>
248
+ }
249
+ : T
package/types/index.d.ts CHANGED
@@ -1,12 +1,9 @@
1
- import { Vue } from "./vue";
2
- import "./umd";
1
+ import { Vue } from './vue'
2
+ import './umd'
3
3
 
4
- export default Vue;
4
+ export default Vue
5
5
 
6
- export {
7
- CreateElement,
8
- VueConstructor
9
- } from "./vue";
6
+ export { CreateElement, VueConstructor } from './vue'
10
7
 
11
8
  export {
12
9
  Component,
@@ -22,12 +19,9 @@ export {
22
19
  WatchOptionsWithHandler,
23
20
  DirectiveFunction,
24
21
  DirectiveOptions
25
- } from "./options";
22
+ } from './options'
26
23
 
27
- export {
28
- PluginFunction,
29
- PluginObject
30
- } from "./plugin";
24
+ export { PluginFunction, PluginObject } from './plugin'
31
25
 
32
26
  export {
33
27
  VNodeChildren,
@@ -36,4 +30,7 @@ export {
36
30
  VNodeComponentOptions,
37
31
  VNodeData,
38
32
  VNodeDirective
39
- } from "./vnode";
33
+ } from './vnode'
34
+
35
+ export * from './v3'
36
+ export * from './v3-generated'