Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
4491164f
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4491164f
编写于
6月 01, 2022
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: rich-text use vnode
上级
251d3844
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
299 addition
and
296 deletion
+299
-296
packages/uni-components/src/vue/rich-text/index.tsx
packages/uni-components/src/vue/rich-text/index.tsx
+12
-69
packages/uni-components/src/vue/rich-text/nodes-parser.ts
packages/uni-components/src/vue/rich-text/nodes-parser.ts
+176
-0
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+55
-120
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+56
-107
未找到文件。
packages/uni-components/src/vue/rich-text/index.tsx
浏览文件 @
4491164f
import
{
onMounted
,
ref
,
watch
,
getCurrentInstance
,
h
,
VNode
}
from
'
vue
'
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
ref
,
watch
,
getCurrentInstance
,
h
,
VNode
}
from
'
vue
'
import
{
defineBuiltInComponent
,
useCustomEvent
,
EmitEvent
,
}
from
'
@dcloudio/uni-components
'
import
parseNodes
,
{
TAGS
,
decodeEntities
}
from
'
./nodes-parser
'
import
{
nodeList2VNode
}
from
'
./nodes-parser
'
import
{
props
,
parseHtml
}
from
'
../../components/rich-text
'
import
{
ssrRef
}
from
'
@dcloudio/uni-app
'
interface
Node
{
type
:
string
text
?:
string
name
:
string
attrs
:
Object
children
:
Node
[]
}
function
_createVNode
(
nodeList
:
Node
[]):
Array
<
VNode
|
undefined
>
{
if
(
!
nodeList
)
return
[]
return
nodeList
.
map
((
node
)
=>
{
if
(
node
.
name
)
{
const
tagName
=
node
.
name
.
toLowerCase
()
if
(
!
hasOwn
(
TAGS
,
tagName
))
{
return
}
}
const
isNode
=
!
hasOwn
(
node
,
'
type
'
)
||
node
.
type
===
'
node
'
return
h
(
isNode
?
node
.
name
:
'
span
'
,
node
.
attrs
,
isNode
?
_createVNode
(
node
.
children
)
:
decodeEntities
(
node
.
text
)
)
})
}
export
default
/*#__PURE__*/
defineBuiltInComponent
({
name
:
'
RichText
'
,
...
...
@@ -49,50 +20,28 @@ export default /*#__PURE__*/ defineBuiltInComponent({
'
touchcancel
'
,
'
touchend
'
,
'
longpress
'
,
'
itemclick
'
,
],
setup
(
props
,
{
emit
,
attrs
})
{
setup
(
props
,
{
emit
})
{
const
vm
=
getCurrentInstance
()
const
scopeId
=
(
vm
&&
vm
.
vnode
.
scopeId
)
||
''
const
rootRef
=
ref
<
HTMLElement
|
null
>
(
null
)
const
nodelist
=
ssrRef
(
props
.
nodes
,
'
nodelist
'
)
const
_vnode
=
ref
<
Array
<
VNode
|
undefined
>>
([]
)
const
trigger
=
useCustomEvent
<
EmitEvent
<
typeof
emit
>>
(
rootRef
,
emit
)
const
hasItemClick
=
!!
attrs
.
onItemclick
function
triggerItemClick
(
e
:
Event
,
detail
=
{})
{
trigger
(
'
itemclick
'
,
e
,
detail
)
}
// ssr 处理
if
(
__NODE_JS__
)
{
if
(
typeof
props
.
nodes
===
'
string
'
)
{
node
list
.
value
=
parseHtml
(
props
.
nodes
)
function
renderVNode
()
{
let
nodeList
=
props
.
nodes
if
(
typeof
nodeList
===
'
string
'
)
{
node
List
=
parseHtml
(
props
.
nodes
)
}
_vnode
.
value
=
nodeList2VNode
(
scopeId
,
triggerItemClick
,
nodeList
as
[])
}
function
_renderNodes
(
nodes
:
string
|
unknown
[])
{
if
(
typeof
nodes
===
'
string
'
)
{
nodelist
.
value
=
parseHtml
(
nodes
)
}
const
nodeList
=
parseNodes
(
nodelist
.
value
,
document
.
createDocumentFragment
(),
scopeId
,
hasItemClick
&&
triggerItemClick
)
rootRef
.
value
!
.
firstElementChild
!
.
innerHTML
=
''
rootRef
.
value
!
.
firstElementChild
!
.
appendChild
(
nodeList
)
}
watch
(
()
=>
props
.
nodes
,
(
value
)
=>
{
_renderNodes
(
value
)
}
)
onMounted
(()
=>
{
_renderNodes
(
nodelist
.
value
as
[])
})
watch
(()
=>
props
.
nodes
,
renderVNode
,
{
immediate
:
true
})
return
()
=>
h
(
...
...
@@ -100,13 +49,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
{
ref
:
rootRef
,
},
[
h
(
'
div
'
,
{},
__NODE_JS__
?
_createVNode
(
nodelist
.
value
as
Node
[])
:
[]
),
]
h
(
'
div
'
,
{},
_vnode
.
value
)
)
},
})
packages/uni-components/src/vue/rich-text/nodes-parser.
j
s
→
packages/uni-components/src/vue/rich-text/nodes-parser.
t
s
浏览文件 @
4491164f
import
{
hasOwn
,
isPlainObject
}
from
'
@vue/shared
'
import
{
hasOwn
,
extend
,
isPlainObject
}
from
'
@vue/shared
'
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
import
{
createTextVNode
,
h
,
VNode
}
from
'
vue
'
export
const
TAGS
=
{
a
:
''
,
...
...
@@ -75,9 +76,18 @@ const CHARS = {
nbsp
:
'
'
,
quot
:
'
"
'
,
apos
:
"
'
"
,
ldquo
:
'
“
'
,
rdquo
:
'
”
'
,
yen
:
'
¥
'
,
radic
:
'
√
'
,
lceil
:
'
⌈
'
,
rceil
:
'
⌉
'
,
lfloor
:
'
⌊
'
,
rfloor
:
'
⌋
'
,
hellip
:
'
…
'
,
}
export
function
decodeEntities
(
htmlString
)
{
export
function
decodeEntities
(
htmlString
:
string
)
{
return
htmlString
.
replace
(
/&
(([
a-zA-Z
]
+
)
|
(
#x
{0,1}[\d
a-zA-Z
]
+
))
;/gi
,
function
(
match
,
stage
)
{
...
...
@@ -88,100 +98,79 @@ export function decodeEntities(htmlString) {
return
String
.
fromCharCode
(
stage
.
slice
(
1
))
}
if
(
/^#x
[
0-9a-f
]{1,4}
$/i
.
test
(
stage
))
{
return
String
.
fromCharCode
(
'
0
'
+
stage
.
slice
(
1
))
}
if
(
!
__NODE_JS__
)
{
const
wrap
=
document
.
createElement
(
'
div
'
)
wrap
.
innerHTML
=
match
return
wrap
.
innerText
||
wrap
.
textContent
}
else
{
return
match
return
String
.
fromCharCode
(
0
+
stage
.
slice
(
1
))
}
return
match
}
)
}
function
normlizeValue
(
tagName
,
name
,
value
)
{
if
(
tagName
===
'
img
'
&&
name
===
'
src
'
)
return
getRealPath
(
value
)
return
value
interface
Node
{
type
:
string
text
?:
string
name
:
string
attrs
:
Data
children
?:
Node
[]
}
function
processClickEvent
(
node
:
Node
,
triggerItemClick
:
Function
)
{
if
([
'
a
'
,
'
img
'
].
includes
(
node
.
name
)
&&
triggerItemClick
)
{
return
{
onClick
:
(
e
:
Event
)
=>
{
triggerItemClick
(
e
,
{
node
})
e
.
stopPropagation
()
e
.
preventDefault
()
e
.
returnValue
=
false
},
}
}
}
export
default
function
parseNodes
(
nodes
,
parentNode
,
scopeId
,
triggerItemClick
)
{
nodes
.
forEach
(
function
(
node
)
{
function
normalizeAttrs
(
tagName
:
string
,
attrs
:
Data
)
{
if
(
!
isPlainObject
(
attrs
))
return
for
(
const
key
in
attrs
)
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
attrs
,
key
))
{
const
value
=
attrs
[
key
]
if
(
tagName
===
'
img
'
&&
key
===
'
src
'
)
attrs
[
key
]
=
getRealPath
(
value
as
string
)
}
}
}
export
const
nodeList2VNode
=
/*#__PURE__*/
(
scopeId
:
string
,
triggerItemClick
:
Function
,
nodeList
?:
Node
[]
):
Array
<
VNode
|
undefined
>
=>
{
if
(
!
nodeList
||
(
Array
.
isArray
(
nodeList
)
&&
!
nodeList
.
length
))
return
[]
return
nodeList
.
map
((
node
)
=>
{
if
(
!
isPlainObject
(
node
))
{
return
}
if
(
!
hasOwn
(
node
,
'
type
'
)
||
node
.
type
===
'
node
'
)
{
if
(
!
(
typeof
node
.
name
===
'
string
'
&&
node
.
name
))
{
return
}
let
nodeProps
=
{}
const
tagName
=
node
.
name
.
toLowerCase
()
if
(
!
hasOwn
(
TAGS
,
tagName
))
{
return
}
const
elem
=
document
.
createElement
(
tagName
)
if
(
!
elem
)
{
return
}
scopeId
&&
elem
.
setAttribute
(
scopeId
,
''
)
const
attrs
=
node
.
attrs
if
(
isPlainObject
(
attrs
))
{
const
tagAttrs
=
TAGS
[
tagName
]
||
[]
Object
.
keys
(
attrs
).
forEach
(
function
(
name
)
{
let
value
=
attrs
[
name
]
switch
(
name
)
{
case
'
class
'
:
/* eslint-disable no-fallthrough */
Array
.
isArray
(
value
)
&&
(
value
=
value
.
join
(
'
'
))
case
'
style
'
:
elem
.
setAttribute
(
name
,
value
)
break
default
:
if
(
tagAttrs
.
indexOf
(
name
)
!==
-
1
)
{
elem
.
setAttribute
(
name
,
normlizeValue
(
tagName
,
name
,
value
))
}
}
})
}
processClickEvent
(
node
,
elem
,
triggerItemClick
)
const
children
=
node
.
children
if
(
Array
.
isArray
(
children
)
&&
children
.
length
)
{
parseNodes
(
node
.
children
,
elem
,
scopeId
,
triggerItemClick
)
}
parentNode
.
appendChild
(
elem
)
}
else
{
if
(
node
.
type
===
'
text
'
&&
typeof
node
.
text
===
'
string
'
&&
node
.
text
!==
''
)
{
parentNode
.
appendChild
(
document
.
createTextNode
(
decodeEntities
(
node
.
text
))
)
}
normalizeAttrs
(
tagName
,
node
.
attrs
)
nodeProps
=
extend
(
nodeProps
,
processClickEvent
(
node
,
triggerItemClick
),
node
.
attrs
)
return
h
(
node
.
name
,
nodeProps
,
nodeList2VNode
(
scopeId
,
triggerItemClick
,
node
.
children
)
)
}
})
return
parentNode
}
function
processClickEvent
(
node
,
elem
,
triggerItemClick
)
{
if
([
'
a
'
,
'
img
'
].
includes
(
node
.
name
)
&&
triggerItemClick
)
{
elem
.
setAttribute
(
'
onClick
'
,
'
return false;
'
)
elem
.
addEventListener
(
'
click
'
,
(
e
)
=>
{
triggerItemClick
(
e
,
{
node
})
e
.
stopPropagation
()
},
true
if
(
node
.
type
===
'
text
'
&&
typeof
node
.
text
===
'
string
'
&&
node
.
text
!==
''
)
}
return
createTextVNode
(
decodeEntities
(
node
.
text
||
''
))
})
}
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
4491164f
...
...
@@ -5017,7 +5017,16 @@ const CHARS = {
lt
:
"
<
"
,
nbsp
:
"
"
,
quot
:
'
"
'
,
apos
:
"
'
"
apos
:
"
'
"
,
ldquo
:
"
\
u201C
"
,
rdquo
:
"
\
u201D
"
,
yen
:
"
\
uFFE5
"
,
radic
:
"
\
u221A
"
,
lceil
:
"
\
u2308
"
,
rceil
:
"
\
u2309
"
,
lfloor
:
"
\
u230A
"
,
rfloor
:
"
\
u230B
"
,
hellip
:
"
\
u2026
"
};
function
decodeEntities
(
htmlString
)
{
return
htmlString
.
replace
(
/&
(([
a-zA-Z
]
+
)
|
(
#x
{0,1}[\d
a-zA-Z
]
+
))
;/gi
,
function
(
match
,
stage
)
{
...
...
@@ -5028,77 +5037,55 @@ function decodeEntities(htmlString) {
return
String
.
fromCharCode
(
stage
.
slice
(
1
));
}
if
(
/^#x
[
0-9a-f
]{1,4}
$/i
.
test
(
stage
))
{
return
String
.
fromCharCode
(
"
0
"
+
stage
.
slice
(
1
));
}
{
return
match
;
return
String
.
fromCharCode
(
0
+
stage
.
slice
(
1
));
}
return
match
;
});
}
function
normlizeValue
(
tagName
,
name
,
value
)
{
if
(
tagName
===
"
img
"
&&
name
===
"
src
"
)
return
getRealPath
(
value
);
return
value
;
function
processClickEvent
(
node
,
triggerItemClick
)
{
if
([
"
a
"
,
"
img
"
].
includes
(
node
.
name
)
&&
triggerItemClick
)
{
return
{
onClick
:
(
e2
)
=>
{
triggerItemClick
(
e2
,
{
node
});
e2
.
stopPropagation
();
e2
.
preventDefault
();
e2
.
returnValue
=
false
;
}
};
}
}
function
parseNodes
(
nodes
,
parentNode
,
scopeId
,
triggerItemClick
)
{
nodes
.
forEach
(
function
(
node
)
{
function
normalizeAttrs
(
tagName
,
attrs
)
{
if
(
!
shared
.
isPlainObject
(
attrs
))
return
;
for
(
const
key
in
attrs
)
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
attrs
,
key
))
{
const
value
=
attrs
[
key
];
if
(
tagName
===
"
img
"
&&
key
===
"
src
"
)
attrs
[
key
]
=
getRealPath
(
value
);
}
}
}
const
nodeList2VNode
=
(
scopeId
,
triggerItemClick
,
nodeList
)
=>
{
if
(
!
nodeList
||
Array
.
isArray
(
nodeList
)
&&
!
nodeList
.
length
)
return
[];
return
nodeList
.
map
((
node
)
=>
{
if
(
!
shared
.
isPlainObject
(
node
))
{
return
;
}
if
(
!
shared
.
hasOwn
(
node
,
"
type
"
)
||
node
.
type
===
"
node
"
)
{
if
(
!
(
typeof
node
.
name
===
"
string
"
&&
node
.
name
))
{
return
;
}
let
nodeProps
=
{};
const
tagName
=
node
.
name
.
toLowerCase
();
if
(
!
shared
.
hasOwn
(
TAGS
,
tagName
))
{
return
;
}
const
elem
=
document
.
createElement
(
tagName
);
if
(
!
elem
)
{
return
;
}
scopeId
&&
elem
.
setAttribute
(
scopeId
,
""
);
const
attrs
=
node
.
attrs
;
if
(
shared
.
isPlainObject
(
attrs
))
{
const
tagAttrs
=
TAGS
[
tagName
]
||
[];
Object
.
keys
(
attrs
).
forEach
(
function
(
name
)
{
let
value
=
attrs
[
name
];
switch
(
name
)
{
case
"
class
"
:
Array
.
isArray
(
value
)
&&
(
value
=
value
.
join
(
"
"
));
case
"
style
"
:
elem
.
setAttribute
(
name
,
value
);
break
;
default
:
if
(
tagAttrs
.
indexOf
(
name
)
!==
-
1
)
{
elem
.
setAttribute
(
name
,
normlizeValue
(
tagName
,
name
,
value
));
}
}
});
}
processClickEvent
(
node
,
elem
,
triggerItemClick
);
const
children
=
node
.
children
;
if
(
Array
.
isArray
(
children
)
&&
children
.
length
)
{
parseNodes
(
node
.
children
,
elem
,
scopeId
,
triggerItemClick
);
}
parentNode
.
appendChild
(
elem
);
}
else
{
if
(
node
.
type
===
"
text
"
&&
typeof
node
.
text
===
"
string
"
&&
node
.
text
!==
""
)
{
parentNode
.
appendChild
(
document
.
createTextNode
(
decodeEntities
(
node
.
text
)));
}
normalizeAttrs
(
tagName
,
node
.
attrs
);
nodeProps
=
shared
.
extend
(
nodeProps
,
processClickEvent
(
node
,
triggerItemClick
),
node
.
attrs
);
return
vue
.
h
(
node
.
name
,
nodeProps
,
nodeList2VNode
(
scopeId
,
triggerItemClick
,
node
.
children
));
}
if
(
node
.
type
===
"
text
"
&&
typeof
node
.
text
===
"
string
"
&&
node
.
text
!==
""
)
return
vue
.
createTextVNode
(
decodeEntities
(
node
.
text
||
""
));
});
return
parentNode
;
}
function
processClickEvent
(
node
,
elem
,
triggerItemClick
)
{
if
([
"
a
"
,
"
img
"
].
includes
(
node
.
name
)
&&
triggerItemClick
)
{
elem
.
setAttribute
(
"
onClick
"
,
"
return false;
"
);
elem
.
addEventListener
(
"
click
"
,
(
e2
)
=>
{
triggerItemClick
(
e2
,
{
node
});
e2
.
stopPropagation
();
},
true
);
}
}
};
function
removeDOCTYPE
(
html
)
{
return
html
.
replace
(
/<
\?
xml.*
\?
>
\n
/
,
""
).
replace
(
/<!doctype.*>
\n
/
,
""
).
replace
(
/<!DOCTYPE.*>
\n
/
,
""
);
}
...
...
@@ -5197,89 +5184,37 @@ const props$g = {
}
}
};
function
getSSRDataType
()
{
return
vue
.
getCurrentInstance
()
?
uniShared
.
UNI_SSR_DATA
:
uniShared
.
UNI_SSR_GLOBAL_DATA
;
}
function
assertKey
(
key
,
shallow
=
false
)
{
if
(
!
key
)
{
throw
new
Error
(
`
${
shallow
?
"
shallowSsrRef
"
:
"
ssrRef
"
}
: You must provide a key.`
);
}
}
const
ssrClientRef
=
(
value
,
key
,
shallow
=
false
)
=>
{
const
valRef
=
shallow
?
vue
.
shallowRef
(
value
)
:
vue
.
ref
(
value
);
if
(
typeof
window
===
"
undefined
"
)
{
return
valRef
;
}
const
__uniSSR
=
window
[
uniShared
.
UNI_SSR
];
if
(
!
__uniSSR
)
{
return
valRef
;
}
const
type
=
getSSRDataType
();
assertKey
(
key
,
shallow
);
if
(
shared
.
hasOwn
(
__uniSSR
[
type
],
key
))
{
valRef
.
value
=
__uniSSR
[
type
][
key
];
if
(
type
===
uniShared
.
UNI_SSR_DATA
)
{
delete
__uniSSR
[
type
][
key
];
}
}
return
valRef
;
};
const
ssrRef
=
(
value
,
key
)
=>
{
return
ssrClientRef
(
value
,
key
);
};
function
_createVNode
(
nodeList
)
{
if
(
!
nodeList
)
return
[];
return
nodeList
.
map
((
node
)
=>
{
if
(
node
.
name
)
{
const
tagName
=
node
.
name
.
toLowerCase
();
if
(
!
shared
.
hasOwn
(
TAGS
,
tagName
))
{
return
;
}
}
const
isNode
=
!
shared
.
hasOwn
(
node
,
"
type
"
)
||
node
.
type
===
"
node
"
;
return
vue
.
h
(
isNode
?
node
.
name
:
"
span
"
,
node
.
attrs
,
isNode
?
_createVNode
(
node
.
children
)
:
decodeEntities
(
node
.
text
));
});
}
var
index$p
=
/* @__PURE__ */
defineBuiltInComponent
({
name
:
"
RichText
"
,
compatConfig
:
{
MODE
:
3
},
props
:
props$g
,
emits
:
[
"
click
"
,
"
touchstart
"
,
"
touchmove
"
,
"
touchcancel
"
,
"
touchend
"
,
"
longpress
"
],
emits
:
[
"
click
"
,
"
touchstart
"
,
"
touchmove
"
,
"
touchcancel
"
,
"
touchend
"
,
"
longpress
"
,
"
itemclick
"
],
setup
(
props2
,
{
emit
:
emit2
,
attrs
emit
:
emit2
})
{
const
vm
=
vue
.
getCurrentInstance
();
const
scopeId
=
vm
&&
vm
.
vnode
.
scopeId
||
""
;
const
rootRef
=
vue
.
ref
(
null
);
const
nodelist
=
ssrRef
(
props2
.
nodes
,
"
nodelist
"
);
const
_vnode
=
vue
.
ref
([]
);
const
trigger
=
useCustomEvent
(
rootRef
,
emit2
);
const
hasItemClick
=
!!
attrs
.
onItemclick
;
function
triggerItemClick
(
e2
,
detail
=
{})
{
trigger
(
"
itemclick
"
,
e2
,
detail
);
}
{
if
(
typeof
props2
.
nodes
===
"
string
"
)
{
nodelist
.
value
=
parseHtml
(
props2
.
nodes
);
}
}
function
_renderNodes
(
nodes
)
{
function
renderVNode
()
{
let
nodes
=
props2
.
nodes
;
if
(
typeof
nodes
===
"
string
"
)
{
node
list
.
value
=
parseHtml
(
nodes
);
node
s
=
parseHtml
(
props2
.
nodes
);
}
const
nodeList
=
parseNodes
(
nodelist
.
value
,
document
.
createDocumentFragment
(),
scopeId
,
hasItemClick
&&
triggerItemClick
);
rootRef
.
value
.
firstElementChild
.
innerHTML
=
""
;
rootRef
.
value
.
firstElementChild
.
appendChild
(
nodeList
);
_vnode
.
value
=
nodeList2VNode
(
scopeId
,
triggerItemClick
,
nodes
);
}
vue
.
watch
(()
=>
props2
.
nodes
,
(
value
)
=>
{
_renderNodes
(
value
);
vue
.
watch
(()
=>
props2
.
nodes
,
renderVNode
,
{
immediate
:
true
});
return
()
=>
vue
.
h
(
"
uni-rich-text
"
,
{
ref
:
rootRef
},
[
vue
.
h
(
"
div
"
,
{},
_createVNode
(
nodelist
.
value
))]
);
},
vue
.
h
(
"
div
"
,
{},
_vnode
.
value
)
);
}
});
const
props$f
=
{
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
4491164f
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, h, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, isArray, remove, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce,
UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR,
ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, sortObject, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, sortObject, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
export { onCreateVueApp } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
...
...
@@ -11704,7 +11704,16 @@ const CHARS = {
lt: "<",
nbsp: " ",
quot: '"',
apos: "'"
apos: "'",
ldquo: "\u201C",
rdquo: "\u201D",
yen: "\uFFE5",
radic: "\u221A",
lceil: "\u2308",
rceil: "\u2309",
lfloor: "\u230A",
rfloor: "\u230B",
hellip: "\u2026"
};
function decodeEntities(htmlString) {
return htmlString.replace(/&(([a-zA-Z]+)|(#x{0,1}[\da-zA-Z]+));/gi, function(match, stage) {
...
...
@@ -11715,79 +11724,55 @@ function decodeEntities(htmlString) {
return String.fromCharCode(stage.slice(1));
}
if (/^#x[0-9a-f]{1,4}$/i.test(stage)) {
return String.fromCharCode("0" + stage.slice(1));
}
{
const wrap = document.createElement("div");
wrap.innerHTML = match;
return wrap.innerText || wrap.textContent;
return String.fromCharCode(0 + stage.slice(1));
}
return match;
});
}
function normlizeValue(tagName, name, value) {
if (tagName === "img" && name === "src")
return getRealPath(value);
return value;
function processClickEvent(node, triggerItemClick) {
if (["a", "img"].includes(node.name) && triggerItemClick) {
return {
onClick: (e2) => {
triggerItemClick(e2, { node });
e2.stopPropagation();
e2.preventDefault();
e2.returnValue = false;
}
};
}
}
function normalizeAttrs(tagName, attrs2) {
if (!isPlainObject(attrs2))
return;
for (const key in attrs2) {
if (Object.prototype.hasOwnProperty.call(attrs2, key)) {
const value = attrs2[key];
if (tagName === "img" && key === "src")
attrs2[key] = getRealPath(value);
}
}
}
function parseNodes(nodes, parentNode, scopeId, triggerItemClick) {
nodes.forEach(function(node) {
const nodeList2VNode = (scopeId, triggerItemClick, nodeList) => {
if (!nodeList || Array.isArray(nodeList) && !nodeList.length)
return [];
return nodeList.map((node) => {
if (!isPlainObject(node)) {
return;
}
if (!hasOwn(node, "type") || node.type === "node") {
if (!(typeof node.name === "string" && node.name)) {
return;
}
let nodeProps = {};
const tagName = node.name.toLowerCase();
if (!hasOwn(TAGS, tagName)) {
return;
}
const elem = document.createElement(tagName);
if (!elem) {
return;
}
scopeId && elem.setAttribute(scopeId, "");
const attrs2 = node.attrs;
if (isPlainObject(attrs2)) {
const tagAttrs = TAGS[tagName] || [];
Object.keys(attrs2).forEach(function(name) {
let value = attrs2[name];
switch (name) {
case "class":
Array.isArray(value) && (value = value.join(" "));
case "style":
elem.setAttribute(name, value);
break;
default:
if (tagAttrs.indexOf(name) !== -1) {
elem.setAttribute(name, normlizeValue(tagName, name, value));
}
}
});
}
processClickEvent(node, elem, triggerItemClick);
const children = node.children;
if (Array.isArray(children) && children.length) {
parseNodes(node.children, elem, scopeId, triggerItemClick);
}
parentNode.appendChild(elem);
} else {
if (node.type === "text" && typeof node.text === "string" && node.text !== "") {
parentNode.appendChild(document.createTextNode(decodeEntities(node.text)));
}
normalizeAttrs(tagName, node.attrs);
nodeProps = extend(nodeProps, processClickEvent(node, triggerItemClick), node.attrs);
return h(node.name, nodeProps, nodeList2VNode(scopeId, triggerItemClick, node.children));
}
if (node.type === "text" && typeof node.text === "string" && node.text !== "")
return createTextVNode(decodeEntities(node.text || ""));
});
return parentNode;
}
function processClickEvent(node, elem, triggerItemClick) {
if (["a", "img"].includes(node.name) && triggerItemClick) {
elem.setAttribute("onClick", "return false;");
elem.addEventListener("click", (e2) => {
triggerItemClick(e2, { node });
e2.stopPropagation();
}, true);
}
}
};
function removeDOCTYPE(html) {
return html.replace(/<\?xml.*\?>\n/, "").replace(/<!doctype.*>\n/, "").replace(/<!DOCTYPE.*>\n/, "");
}
...
...
@@ -11886,73 +11871,37 @@ const props$n = {
}
}
};
function getSSRDataType() {
return getCurrentInstance() ? UNI_SSR_DATA : UNI_SSR_GLOBAL_DATA;
}
function assertKey(key, shallow = false) {
if (!key) {
throw new Error(`${shallow ? "shallowSsrRef" : "ssrRef"}: You must provide a key.`);
}
}
const ssrClientRef = (value, key, shallow = false) => {
const valRef = shallow ? shallowRef(value) : ref(value);
if (typeof window === "undefined") {
return valRef;
}
const __uniSSR = window[UNI_SSR];
if (!__uniSSR) {
return valRef;
}
const type = getSSRDataType();
assertKey(key, shallow);
if (hasOwn(__uniSSR[type], key)) {
valRef.value = __uniSSR[type][key];
if (type === UNI_SSR_DATA) {
delete __uniSSR[type][key];
}
}
return valRef;
};
const ssrRef = (value, key) => {
return ssrClientRef(value, key);
};
var index$m = /* @__PURE__ */ defineBuiltInComponent({
name: "RichText",
compatConfig: {
MODE: 3
},
props: props$n,
emits: ["click", "touchstart", "touchmove", "touchcancel", "touchend", "longpress"],
emits: ["click", "touchstart", "touchmove", "touchcancel", "touchend", "longpress"
, "itemclick"
],
setup(props2, {
emit: emit2,
attrs: attrs2
emit: emit2
}) {
const vm = getCurrentInstance();
const scopeId = vm && vm.vnode.scopeId || "";
const rootRef = ref(null);
const
nodelist = ssrRef(props2.nodes, "nodelist"
);
const
_vnode = ref([]
);
const trigger = useCustomEvent(rootRef, emit2);
const hasItemClick = !!attrs2.onItemclick;
function triggerItemClick(e2, detail = {}) {
trigger("itemclick", e2, detail);
}
function _renderNodes(nodes) {
function renderVNode() {
let nodes = props2.nodes;
if (typeof nodes === "string") {
node
list.value = parseHtml(
nodes);
node
s = parseHtml(props2.
nodes);
}
const nodeList = parseNodes(nodelist.value, document.createDocumentFragment(), scopeId, hasItemClick && triggerItemClick);
rootRef.value.firstElementChild.innerHTML = "";
rootRef.value.firstElementChild.appendChild(nodeList);
_vnode.value = nodeList2VNode(scopeId, triggerItemClick, nodes);
}
watch(() => props2.nodes, (value) => {
_renderNodes(value);
});
onMounted(() => {
_renderNodes(nodelist.value);
watch(() => props2.nodes, renderVNode, {
immediate: true
});
return () => h("uni-rich-text", {
ref: rootRef
},
[h("div", {}, [])]
);
},
h("div", {}, _vnode.value)
);
}
});
const passiveOptions = /* @__PURE__ */ passive(true);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录