提交 244c4e05 编写于 作者: fxy060608's avatar fxy060608

wip(app): uni-app-plus

上级 6a793afb
...@@ -3,212 +3,6 @@ import { decodeActions } from '../../../src/service/framework/dom/decodeActions' ...@@ -3,212 +3,6 @@ import { decodeActions } from '../../../src/service/framework/dom/decodeActions'
describe('decode', () => { describe('decode', () => {
test('actions', () => { test('actions', () => {
console.log( console.log(inspect(decodeActions([]), { colors: true, depth: null }))
inspect(
decodeActions([
[3, 1, 4],
[3, 2, 4],
[
4,
1,
0,
-1,
{
t: '',
},
],
[
4,
2,
0,
-1,
{
t: '',
},
],
[3, 3, 1],
[
4,
3,
0,
2,
{
a: {
'.e0': 0,
},
t: '跳转二级页面',
},
],
[3, 4, 1],
[3, 5, 1],
[
4,
5,
4,
-1,
{
a: {
'.e0': 0,
},
t: '123aaaaaaaaaaaa',
},
],
[
4,
4,
0,
2,
{
a: {
'.c': 'content',
'.h0': 'none',
},
},
],
[3, 6, 4],
[3, 7, 4],
[
4,
6,
0,
2,
{
t: '',
},
],
[
4,
7,
0,
2,
{
t: '',
},
],
[3, 8, 1],
[
4,
8,
0,
7,
{
a: {
'.e0': 0,
},
t: '1test...........',
},
],
[3, 9, 1],
[
4,
9,
0,
7,
{
t: '2',
},
],
[3, 10, 1],
[
4,
10,
0,
2,
{
a: {
'.e0': 0,
},
t: 'showModal',
},
],
[3, 11, 1],
[
4,
11,
0,
2,
{
a: {
'.c': 'title',
},
t: '456',
},
],
[3, 12, 1],
[
4,
12,
0,
2,
{
a: {
'.e0': 0,
},
t: '切换hover',
},
],
[3, 13, 1],
[
4,
13,
0,
2,
{
a: {
'.s': {
color: 'red',
},
},
t: 'static style',
},
],
[3, 14, 1],
[
4,
14,
0,
2,
{
a: {
'.s': {
color: 'red',
},
},
t: 'dynamic obj style',
},
],
[3, 15, 1],
[
4,
15,
0,
2,
{
a: {
'.s': {
color: 'black',
},
},
t: 'dynamic array style',
},
],
[3, 16, 1],
[
4,
16,
0,
2,
{
a: {
'.s': 'color:blue',
},
t: 'dynamic string style',
},
],
[2],
]),
{ colors: true, depth: null }
)
)
}) })
}) })
import { UniEventListener, UniNodeJSON } from '@dcloudio/uni-shared' import { UniEventListener } from '@dcloudio/uni-shared'
import { createPageNode } from '../../../src/service/framework/dom/Page' import { createPageNode } from '../../../src/service/framework/dom/Page'
import { import {
createElement, createElement,
...@@ -45,8 +45,6 @@ describe('dom', () => { ...@@ -45,8 +45,6 @@ describe('dom', () => {
expect(addElementAction[1]).toBe(1) // nodeId expect(addElementAction[1]).toBe(1) // nodeId
expect(addElementAction[2]).toBe(0) // parentNodeId expect(addElementAction[2]).toBe(0) // parentNodeId
expect(addElementAction[3]).toBe(-1) // index expect(addElementAction[3]).toBe(-1) // index
const elementJson = addElementAction[4] as UniNodeJSON
expect(elementJson.a.id).toBe('view')
const setAttributeAction = updateActions[1] as SetAttributeAction const setAttributeAction = updateActions[1] as SetAttributeAction
expect(setAttributeAction[0]).toBe(ACTION_TYPE_SET_ATTRIBUTE) expect(setAttributeAction[0]).toBe(ACTION_TYPE_SET_ATTRIBUTE)
...@@ -90,8 +88,6 @@ describe('dom', () => { ...@@ -90,8 +88,6 @@ describe('dom', () => {
expect(addTextNodeAction[1]).toBe(2) expect(addTextNodeAction[1]).toBe(2)
expect(addTextNodeAction[2]).toBe(0) expect(addTextNodeAction[2]).toBe(0)
expect(addTextNodeAction[3]).toBe(-1) expect(addTextNodeAction[3]).toBe(-1)
const textNodeJson = addTextNodeAction[4] as UniNodeJSON
expect(textNodeJson.t).toBe('hello')
root.updateActions.length = 0 root.updateActions.length = 0
const clickFn = () => {} const clickFn = () => {}
......
...@@ -75,8 +75,8 @@ ...@@ -75,8 +75,8 @@
function decodePageCreatedAction([]) { function decodePageCreatedAction([]) {
return ['pageCreated']; return ['pageCreated'];
} }
function decodeCreateAction([, nodeId, nodeName, nodeJson]) { function decodeCreateAction([, nodeId, nodeName, parentNodeId, nodeJson,]) {
return ['create', nodeId, decodeTag(nodeName), nodeJson]; return ['create', nodeId, decodeTag(nodeName), parentNodeId, nodeJson];
} }
function decodeInsertAction([, ...action]) { function decodeInsertAction([, ...action]) {
return ['insert', ...action]; return ['insert', ...action];
......
...@@ -7373,7 +7373,10 @@ var serviceContext = (function (vue) { ...@@ -7373,7 +7373,10 @@ var serviceContext = (function (vue) {
case ACTION_TYPE_INSERT: case ACTION_TYPE_INSERT:
const createAction = this._createActionMap.get(action[1]); const createAction = this._createActionMap.get(action[1]);
if (createAction) { if (createAction) {
createAction[3] = extras; createAction[3] = action[2]; // parentNodeId
if (extras) {
createAction[4] = extras;
}
} }
else { else {
if ((process.env.NODE_ENV !== 'production')) { if ((process.env.NODE_ENV !== 'production')) {
...@@ -7439,7 +7442,7 @@ var serviceContext = (function (vue) { ...@@ -7439,7 +7442,7 @@ var serviceContext = (function (vue) {
return null; return null;
} }
function pushCreateAction(pageNode, nodeId, nodeName) { function pushCreateAction(pageNode, nodeId, nodeName) {
pageNode.push([ACTION_TYPE_CREATE, nodeId, nodeName]); pageNode.push([ACTION_TYPE_CREATE, nodeId, nodeName, -1]);
} }
function pushInsertAction(pageNode, newChild, parentNodeId, refChildId) { function pushInsertAction(pageNode, newChild, parentNodeId, refChildId) {
const nodeJson = newChild.toJSON({ attr: true }); const nodeJson = newChild.toJSON({ attr: true });
......
...@@ -115,7 +115,10 @@ export default class UniPageNode extends UniNode implements IUniPageNode { ...@@ -115,7 +115,10 @@ export default class UniPageNode extends UniNode implements IUniPageNode {
case ACTION_TYPE_INSERT: case ACTION_TYPE_INSERT:
const createAction = this._createActionMap.get(action[1]) const createAction = this._createActionMap.get(action[1])
if (createAction) { if (createAction) {
createAction[3] = extras as UniNodeJSON createAction[3] = action[2] // parentNodeId
if (extras) {
createAction[4] = extras as UniNodeJSON
}
} else { } else {
if (__DEV__) { if (__DEV__) {
console.error(formatLog(`Insert`, action, 'not found createAction')) console.error(formatLog(`Insert`, action, 'not found createAction'))
...@@ -124,9 +127,6 @@ export default class UniPageNode extends UniNode implements IUniPageNode { ...@@ -124,9 +127,6 @@ export default class UniPageNode extends UniNode implements IUniPageNode {
break break
} }
this.updateActions.push(action) this.updateActions.push(action)
if (__DEV__) {
console.log(formatLog('PageNode', 'push', action))
}
queuePostFlushCb(this._update) queuePostFlushCb(this._update)
} }
restore() { restore() {
...@@ -192,7 +192,7 @@ function pushCreateAction( ...@@ -192,7 +192,7 @@ function pushCreateAction(
nodeId: number, nodeId: number,
nodeName: string | number nodeName: string | number
) { ) {
pageNode.push([ACTION_TYPE_CREATE, nodeId, nodeName]) pageNode.push([ACTION_TYPE_CREATE, nodeId, nodeName, -1])
} }
function pushInsertAction( function pushInsertAction(
......
...@@ -27,8 +27,14 @@ function decodePageCreatedAction([]: PageCreatedAction) { ...@@ -27,8 +27,14 @@ function decodePageCreatedAction([]: PageCreatedAction) {
return ['pageCreated'] return ['pageCreated']
} }
function decodeCreateAction([, nodeId, nodeName, nodeJson]: CreateAction) { function decodeCreateAction([
return ['create', nodeId, decodeTag(nodeName), nodeJson] ,
nodeId,
nodeName,
parentNodeId,
nodeJson,
]: CreateAction) {
return ['create', nodeId, decodeTag(nodeName), parentNodeId, nodeJson]
} }
function decodeInsertAction([, ...action]: InsertAction) { function decodeInsertAction([, ...action]: InsertAction) {
......
...@@ -4,7 +4,11 @@ import Ad from '../../../components/ad' ...@@ -4,7 +4,11 @@ import Ad from '../../../components/ad'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniAd extends UniComponent { export class UniAd extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-ad', Ad, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-ad', Ad, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniAudio extends UniComponent { export class UniAudio extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-audio', Audio, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-audio', Audio, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniButton extends UniComponent { export class UniButton extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-button', Button, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-button', Button, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniCanvas extends UniComponent { export class UniCanvas extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-canvas', Canvas, nodeJson, 'canvas > div') id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-canvas', Canvas, parentNodeId, nodeJson, 'canvas > div')
} }
} }
...@@ -4,7 +4,18 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,18 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniCheckbox extends UniComponent { export class UniCheckbox extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-checkbox', Checkbox, nodeJson, '.uni-checkbox-wrapper') id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(
id,
'uni-checkbox',
Checkbox,
parentNodeId,
nodeJson,
'.uni-checkbox-wrapper'
)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniCheckboxGroup extends UniComponent { export class UniCheckboxGroup extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-checkbox-group', CheckboxGroup, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-checkbox-group', CheckboxGroup, parentNodeId, nodeJson)
} }
} }
import { hasOwn } from '@vue/shared' import { hasOwn } from '@vue/shared'
import { Component, createApp, reactive } from 'vue' import { Component, createApp, reactive } from 'vue'
import { import { decodeAttr, parseEventName, UniNodeJSON } from '@dcloudio/uni-shared'
decodeAttr,
// formatLog,
parseEventName,
UniNodeJSON,
} from '@dcloudio/uni-shared'
import { UniNode } from '../elements/UniNode' import { UniNode } from '../elements/UniNode'
import { createInvoker } from '../modules/events' import { createInvoker } from '../modules/events'
import { createWrapper } from '.' import { createWrapper, UniCustomElement } from '.'
export class UniComponent extends UniNode { export class UniComponent extends UniNode {
declare $: Element declare $: UniCustomElement
private $props!: Record<string, any> private $props!: Record<string, any>
private $holder?: Element private $holder?: Element
// private $fragment: DocumentFragment | null = null
constructor( constructor(
id: number, id: number,
tag: string, tag: string,
component: Component, component: Component,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>, nodeJson: Partial<UniNodeJSON>,
selector?: string selector?: string
) { ) {
...@@ -27,7 +22,7 @@ export class UniComponent extends UniNode { ...@@ -27,7 +22,7 @@ export class UniComponent extends UniNode {
this.$props = reactive({}) this.$props = reactive({})
this.init(nodeJson) this.init(nodeJson)
createApp(createWrapper(component, this.$props)).mount(container) createApp(createWrapper(component, this.$props)).mount(container)
this.$ = container.firstElementChild! this.$ = container.firstElementChild! as UniCustomElement
if (selector) { if (selector) {
this.$holder = this.$.querySelector(selector)! this.$holder = this.$.querySelector(selector)!
} }
...@@ -61,40 +56,10 @@ export class UniComponent extends UniNode { ...@@ -61,40 +56,10 @@ export class UniComponent extends UniNode {
removeAttr(name: string) { removeAttr(name: string) {
this.$props[decodeAttr(name)] = null this.$props[decodeAttr(name)] = null
} }
// get fragment() {
// if (!this.$fragment) {
// this.$fragment = document.createDocumentFragment()
// }
// return this.$fragment
// }
appendChild(node: Element) { appendChild(node: Element) {
// if (!this.$) {
// // 可能还未初始化,临时存放
// if (__DEV__) {
// console.log(
// formatLog(this.tag, 'fragment', 'appendChild', node.tagName)
// )
// }
// return this.fragment.appendChild(node)
// }
return (this.$holder || this.$).appendChild(node) return (this.$holder || this.$).appendChild(node)
} }
insertBefore(newChild: Node, refChild: Node) { insertBefore(newChild: Node, refChild: Node) {
// if (!this.$) {
// // 可能还未初始化,临时存放
// if (__DEV__) {
// console.log(
// formatLog(
// this.tag,
// 'fragment',
// 'insertBefore',
// (newChild as Element).tagName,
// (refChild as Element).tagName
// )
// )
// }
// return this.fragment.insertBefore(newChild, refChild)
// }
return (this.$holder || this.$).insertBefore(newChild, refChild) return (this.$holder || this.$).insertBefore(newChild, refChild)
} }
} }
...@@ -4,7 +4,11 @@ import CoverImage from '../../../components/cover-image' ...@@ -4,7 +4,11 @@ import CoverImage from '../../../components/cover-image'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniCoverImage extends UniComponent { export class UniCoverImage extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-cover-image', CoverImage, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-cover-image', CoverImage, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import CoverView from '../../../components/cover-view' ...@@ -4,7 +4,11 @@ import CoverView from '../../../components/cover-view'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniCoverView extends UniComponent { export class UniCoverView extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-cover-view', CoverView, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-cover-view', CoverView, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniEditor extends UniComponent { export class UniEditor extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-editor', Editor, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-editor', Editor, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniForm extends UniComponent { export class UniForm extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-form', Form, nodeJson, 'span') id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-form', Form, parentNodeId, nodeJson, 'span')
} }
} }
...@@ -5,7 +5,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -5,7 +5,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniIcon extends UniComponent { export class UniIcon extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-icon', Icon, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-icon', Icon, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniImage extends UniComponent { export class UniImage extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-image', Image, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-image', Image, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniInput extends UniComponent { export class UniInput extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-input', Input, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-input', Input, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniLabel extends UniComponent { export class UniLabel extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-label', Label, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-label', Label, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import Map from '../../../components/map' ...@@ -4,7 +4,11 @@ import Map from '../../../components/map'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniMap extends UniComponent { export class UniMap extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-map', Map, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-map', Map, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniMovableArea extends UniComponent { export class UniMovableArea extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-movable-area', MovableArea, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-movable-area', MovableArea, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniMovableView extends UniComponent { export class UniMovableView extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-movable-view', MovableView, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-movable-view', MovableView, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniNavigator extends UniComponent { export class UniNavigator extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-navigator', Navigator, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-navigator', Navigator, parentNodeId, nodeJson)
} }
} }
...@@ -3,7 +3,11 @@ import Picker from '../../../components/picker' ...@@ -3,7 +3,11 @@ import Picker from '../../../components/picker'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniPicker extends UniComponent { export class UniPicker extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-picker', Picker, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-picker', Picker, parentNodeId, nodeJson)
} }
} }
...@@ -4,11 +4,16 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,11 +4,16 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniPickerView extends UniComponent { export class UniPickerView extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super( super(
id, id,
'uni-picker-view', 'uni-picker-view',
PickerView, PickerView,
parentNodeId,
nodeJson, nodeJson,
'.uni-picker-view-wrapper' '.uni-picker-view-wrapper'
) )
......
...@@ -4,11 +4,16 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,11 +4,16 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniPickerViewColumn extends UniComponent { export class UniPickerViewColumn extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super( super(
id, id,
'uni-picker-view-column', 'uni-picker-view-column',
PickerViewColumn, PickerViewColumn,
parentNodeId,
nodeJson, nodeJson,
'.uni-picker-view-content' '.uni-picker-view-content'
) )
......
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniProgress extends UniComponent { export class UniProgress extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-progress', Progress, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-progress', Progress, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniRadio extends UniComponent { export class UniRadio extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-radio', Radio, nodeJson, '.uni-radio-wrapper') id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-radio', Radio, parentNodeId, nodeJson, '.uni-radio-wrapper')
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniRadioGroup extends UniComponent { export class UniRadioGroup extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-radio-group', RadioGroup, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-radio-group', RadioGroup, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniRichText extends UniComponent { export class UniRichText extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-rich-text', RichText, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-rich-text', RichText, parentNodeId, nodeJson)
} }
} }
...@@ -4,11 +4,16 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,11 +4,16 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniScrollView extends UniComponent { export class UniScrollView extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super( super(
id, id,
'uni-scroll-view', 'uni-scroll-view',
ScrollView, ScrollView,
parentNodeId,
nodeJson, nodeJson,
'.uni-scroll-view-content' '.uni-scroll-view-content'
) )
......
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniSlider extends UniComponent { export class UniSlider extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-slider', Slider, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-slider', Slider, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,18 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,18 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniSwiper extends UniComponent { export class UniSwiper extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-swiper', Swiper, nodeJson, '.uni-swiper-slide-frame') id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(
id,
'uni-swiper',
Swiper,
parentNodeId,
nodeJson,
'.uni-swiper-slide-frame'
)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniSwiperItem extends UniComponent { export class UniSwiperItem extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-swiper-item', SwiperItem, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-swiper-item', SwiperItem, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniSwitch extends UniComponent { export class UniSwitch extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-switch', Switch, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-switch', Switch, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared' ...@@ -4,7 +4,11 @@ import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniTextarea extends UniComponent { export class UniTextarea extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-textarea', Textarea, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-textarea', Textarea, parentNodeId, nodeJson)
} }
} }
...@@ -5,7 +5,11 @@ import Video from '../../../components/video' ...@@ -5,7 +5,11 @@ import Video from '../../../components/video'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniVideo extends UniComponent { export class UniVideo extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-video', Video, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-video', Video, parentNodeId, nodeJson)
} }
} }
...@@ -4,7 +4,11 @@ import WebView from '../../../components/web-view' ...@@ -4,7 +4,11 @@ import WebView from '../../../components/web-view'
import { UniComponent } from './UniComponent' import { UniComponent } from './UniComponent'
export class UniWebView extends UniComponent { export class UniWebView extends UniComponent {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
super(id, 'uni-web-view', WebView, nodeJson) id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, 'uni-web-view', WebView, parentNodeId, nodeJson)
} }
} }
import { UniNodeJSON } from '@dcloudio/uni-shared' import { UniNodeJSON } from '@dcloudio/uni-shared'
import { defineComponent, h } from 'vue' import { ComponentPublicInstance, defineComponent, h } from 'vue'
import { UniComment } from '../elements/UniComment' import { UniComment } from '../elements/UniComment'
import { UniTextElement } from '../elements/UniTextElement' import { UniTextElement } from '../elements/UniTextElement'
import { UniTextNode } from '../elements/UniTextNode' import { UniTextNode } from '../elements/UniTextNode'
...@@ -46,6 +46,7 @@ import { UniWebView } from './UniWebView' ...@@ -46,6 +46,7 @@ import { UniWebView } from './UniWebView'
export interface UniCustomElement extends Element { export interface UniCustomElement extends Element {
__id: number __id: number
__vm: ComponentPublicInstance
__listeners: Record<string, (evt: Event) => void> __listeners: Record<string, (evt: Event) => void>
} }
...@@ -101,9 +102,10 @@ export type WrapperComponent = ReturnType<typeof createWrapper> ...@@ -101,9 +102,10 @@ export type WrapperComponent = ReturnType<typeof createWrapper>
export function createBuiltInComponent( export function createBuiltInComponent(
type: number, type: number,
id: number, id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON> nodeJson: Partial<UniNodeJSON>
) { ) {
return new BuiltInComponents[type]!(id, nodeJson) return new BuiltInComponents[type]!(id, parentNodeId, nodeJson)
} }
export function createWrapper( export function createWrapper(
......
...@@ -13,7 +13,11 @@ const PROP_NAMES_HOVER = ['space', 'decode'] ...@@ -13,7 +13,11 @@ const PROP_NAMES_HOVER = ['space', 'decode']
export class UniTextElement extends UniElement<TextProps> { export class UniTextElement extends UniElement<TextProps> {
private _text: string = '' private _text: string = ''
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
id: number,
_parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, document.createElement('uni-text'), nodeJson, PROP_NAMES_HOVER) super(id, document.createElement('uni-text'), nodeJson, PROP_NAMES_HOVER)
} }
......
...@@ -2,7 +2,11 @@ import '@dcloudio/uni-components/style/view.css' ...@@ -2,7 +2,11 @@ import '@dcloudio/uni-components/style/view.css'
import { UniNodeJSON } from '@dcloudio/uni-shared' import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniHoverElement } from './UniHoverElement' import { UniHoverElement } from './UniHoverElement'
export class UniViewElement extends UniHoverElement { export class UniViewElement extends UniHoverElement {
constructor(id: number, nodeJson: Partial<UniNodeJSON>) { constructor(
id: number,
_parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, document.createElement('uni-view'), nodeJson) super(id, document.createElement('uni-view'), nodeJson)
} }
} }
...@@ -20,7 +20,7 @@ export function onVdSync(actions: PageAction[]) { ...@@ -20,7 +20,7 @@ export function onVdSync(actions: PageAction[]) {
case ACTION_TYPE_PAGE_CREATED: case ACTION_TYPE_PAGE_CREATED:
return onPageCreated() return onPageCreated()
case ACTION_TYPE_CREATE: case ACTION_TYPE_CREATE:
return createElement(action[1], action[2], action[3]) return createElement(action[1], action[2], action[3], action[4])
case ACTION_TYPE_INSERT: case ACTION_TYPE_INSERT:
return $(action[1]).insert(action[2], action[3]) return $(action[1]).insert(action[2], action[3])
case ACTION_TYPE_REMOVE: case ACTION_TYPE_REMOVE:
......
...@@ -22,6 +22,7 @@ export function $(id: number) { ...@@ -22,6 +22,7 @@ export function $(id: number) {
export function createElement( export function createElement(
id: number, id: number,
tag: string | number, tag: string | number,
parentNodeId?: number,
nodeJson: Partial<UniNodeJSON> = {} nodeJson: Partial<UniNodeJSON> = {}
) { ) {
let element: UniNode let element: UniNode
...@@ -35,7 +36,7 @@ export function createElement( ...@@ -35,7 +36,7 @@ export function createElement(
} else if (isString(tag)) { } else if (isString(tag)) {
element = new UniElement(id, document.createElement(tag), nodeJson) element = new UniElement(id, document.createElement(tag), nodeJson)
} else { } else {
element = createBuiltInComponent(tag, id, nodeJson) element = createBuiltInComponent(tag, id, parentNodeId!, nodeJson)
} }
elements.set(id, element) elements.set(id, element)
return element return element
...@@ -91,7 +92,7 @@ function initSystemInfo( ...@@ -91,7 +92,7 @@ function initSystemInfo(
} }
function initPageElement() { function initPageElement() {
createElement(0, 'div', {}).$ = document.getElementById('app')! createElement(0, 'div').$ = document.getElementById('app')!
} }
function initPageCss(route: string) { function initPageCss(route: string) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册