提交 fd0eb655 编写于 作者: Q qiang

fix(App): movable/picker-view/picker-view-column use rebuild

上级 59b977ee
......@@ -3486,29 +3486,26 @@ var serviceContext = (function (vue) {
return new ServiceMediaQueryObserver(getCurrentPageVm());
});
let eventReady = false;
// let eventReady = false
let index$2 = 0;
let optionsCache = {};
function operateEditor(componentId, pageId, type, options) {
const data = {};
if (options &&
('success' in options || 'fail' in options || 'complete' in options)) {
const data = { options };
const needCallOptions = options &&
('success' in options || 'fail' in options || 'complete' in options);
if (needCallOptions) {
const callbackId = String(index$2++);
data.callbackId = callbackId;
optionsCache[callbackId] = options;
if (!eventReady) {
UniServiceJSBridge.subscribe('onEditorMethodCallback', ({ callbackId, data }) => {
callOptions(optionsCache[callbackId], data);
delete optionsCache[callbackId];
});
eventReady = true;
}
}
data.options = options;
UniServiceJSBridge.publishHandler('editor.' + componentId, {
componentId,
UniServiceJSBridge.invokeViewMethod(`editor.${componentId}`, {
type,
data,
}, ({ callbackId, data }) => {
if (needCallOptions) {
callOptions(optionsCache[callbackId], data);
delete optionsCache[callbackId];
}
}, pageId);
}
class EditorContext {
......
......@@ -10,6 +10,7 @@ var __publicField = (obj, key, value) => {
"use strict";
var base = "* {\n margin: 0;\n -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\n -webkit-tap-highlight-color: transparent;\n}\n\nhtml,\nbody {\n -webkit-user-select: none;\n user-select: none;\n width: 100%;\n}\n\nhtml {\n height: 100%;\n height: 100vh;\n width: 100%;\n width: 100vw;\n}\n\nbody {\n overflow-x: hidden;\n background-color: white;\n}\n\ninput[type='search']::-webkit-search-cancel-button {\n display: none;\n}\n\n.uni-loading,\nuni-button[loading]:before {\n background: transparent\n url('data:image/svg+xml;base64, PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iMTIwIiB2aWV3Qm94PSIwIDAgMTAwIDEwMCI+PHBhdGggZmlsbD0ibm9uZSIgZD0iTTAgMGgxMDB2MTAwSDB6Ii8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTlFOUU5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTMwKSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iIzk4OTY5NyIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgzMCAxMDUuOTggNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjOUI5OTlBIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDYwIDc1Ljk4IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0EzQTFBMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSg5MCA2NSA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNBQkE5QUEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoMTIwIDU4LjY2IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0IyQjJCMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgxNTAgNTQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjQkFCOEI5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDE4MCA1MCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDMkMwQzEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTE1MCA0NS45OCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDQkNCQ0IiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTEyMCA0MS4zNCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNEMkQyRDIiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTkwIDM1IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0RBREFEQSIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgtNjAgMjQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTJFMkUyIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKC0zMCAtNS45OCA2NSkiLz48L3N2Zz4=')\n no-repeat;\n}\n\n.uni-loading {\n width: 20px;\n height: 20px;\n display: inline-block;\n vertical-align: middle;\n animation: uni-loading 1s steps(12, end) infinite;\n background-size: 100%;\n}\n\n@keyframes uni-loading {\n 0% {\n transform: rotate3d(0, 0, 1, 0deg);\n }\n\n 100% {\n transform: rotate3d(0, 0, 1, 360deg);\n }\n}\n";
var nvue = "[nvue] uni-view,\n[nvue] uni-label,\n[nvue] uni-swiper-item,\n[nvue] uni-scroll-view {\n display: flex;\n flex-shrink: 0;\n flex-grow: 0;\n flex-basis: auto;\n align-items: stretch;\n align-content: flex-start;\n}\n\n[nvue] uni-button {\n margin: 0;\n}\n\n[nvue-dir-row] uni-view,\n[nvue-dir-row] uni-label,\n[nvue-dir-row] uni-swiper-item {\n flex-direction: row;\n}\n\n[nvue-dir-column] uni-view,\n[nvue-dir-column] uni-label,\n[nvue-dir-column] uni-swiper-item {\n flex-direction: column;\n}\n\n[nvue-dir-row-reverse] uni-view,\n[nvue-dir-row-reverse] uni-label,\n[nvue-dir-row-reverse] uni-swiper-item {\n flex-direction: row-reverse;\n}\n\n[nvue-dir-column-reverse] uni-view,\n[nvue-dir-column-reverse] uni-label,\n[nvue-dir-column-reverse] uni-swiper-item {\n flex-direction: column-reverse;\n}\n\n[nvue] uni-view,\n[nvue] uni-image,\n[nvue] uni-input,\n[nvue] uni-scroll-view,\n[nvue] uni-swiper,\n[nvue] uni-swiper-item,\n[nvue] uni-text,\n[nvue] uni-textarea,\n[nvue] uni-video {\n position: relative;\n border: 0px solid #000000;\n box-sizing: border-box;\n}\n\n[nvue] uni-swiper-item {\n position: absolute;\n}\n";
var resizeSensor = "@keyframes once-show {\n from {\n top: 0;\n }\n}\nuni-resize-sensor,\nuni-resize-sensor > div {\n position: absolute;\n left: 0;\n top: 0;\n right: 0;\n bottom: 0;\n overflow: hidden;\n}\nuni-resize-sensor {\n display: block;\n z-index: -1;\n visibility: hidden;\n animation: once-show 1ms;\n}\nuni-resize-sensor > div > div {\n position: absolute;\n left: 0;\n top: 0;\n}\nuni-resize-sensor > div:first-child > div {\n width: 100000px;\n height: 100000px;\n}\nuni-resize-sensor > div:last-child > div {\n width: 200%;\n height: 200%;\n}\n";
function makeMap$1(str, expectsLowerCase) {
const map = Object.create(null);
const list2 = str.split(",");
......@@ -8460,8 +8461,7 @@ var __publicField = (obj, key, value) => {
}
});
});
const id2 = useContextInfo();
useSubscribe((type, data) => {
registerViewMethod(getCurrentPageId(), `editor.${props2.id}`, ({ type, data }, resolve) => {
const { options, callbackId } = data;
let res;
let range;
......@@ -8598,14 +8598,14 @@ var __publicField = (obj, key, value) => {
errMsg = "not ready";
}
if (callbackId) {
UniViewJSBridge.publishHandler("onEditorMethodCallback", {
resolve({
callbackId,
data: extend({}, res, {
errMsg: `${type}:${errMsg ? "fail " + errMsg : "ok"}`
})
});
}
}, id2, true);
});
}
const props$j = /* @__PURE__ */ extend({}, props$k, {
id: {
......@@ -9548,6 +9548,10 @@ var __publicField = (obj, key, value) => {
}
return array;
}
function useRebuild(callback) {
const instance = getCurrentInstance();
instance.rebuild = callback;
}
const props$f = {
scaleArea: {
type: Boolean,
......@@ -9589,14 +9593,23 @@ var __publicField = (obj, key, value) => {
function updateMovableViewContexts() {
const contexts = [];
for (let index2 = 0; index2 < movableViewItems.length; index2++) {
const movableViewItem = movableViewItems[index2];
const movableViewContext = originMovableViewContexts.find((context) => movableViewItem.el === context.rootRef.value);
let movableViewItem = movableViewItems[index2];
if (!(movableViewItem instanceof Element)) {
movableViewItem = movableViewItem.el;
}
const movableViewContext = originMovableViewContexts.find((context) => movableViewItem === context.rootRef.value);
if (movableViewContext) {
contexts.push(markRaw(movableViewContext));
}
}
setContexts(contexts);
}
{
useRebuild(() => {
movableViewItems = rootRef.value.children;
updateMovableViewContexts();
});
}
const addMovableViewContext = (movableViewContext) => {
originMovableViewContexts.push(movableViewContext);
updateMovableViewContexts();
......@@ -9613,8 +9626,7 @@ var __publicField = (obj, key, value) => {
provide("addMovableViewContext", addMovableViewContext);
provide("removeMovableViewContext", removeMovableViewContext);
return () => {
const defaultSlots = slots.default && slots.default();
movableViewItems = flatVNode(defaultSlots);
slots.default && slots.default();
return createVNode("uni-movable-area", mergeProps({
"ref": rootRef
}, $attrs.value, $excludeAttrs.value, _listeners), {
......@@ -10970,15 +10982,20 @@ var __publicField = (obj, key, value) => {
emit: emit2
}) {
const rootRef = ref(null);
const wrapperRef = ref(null);
const trigger2 = useCustomEvent(rootRef, emit2);
const state = useState$1(props2);
const resizeSensorRef = ref(null);
onMounted(() => {
const resizeSensor = resizeSensorRef.value;
state.height = resizeSensor.$el.getBoundingClientRect().height;
});
let columnVNodes = [];
const onMountedCallback = () => {
const resizeSensor2 = resizeSensorRef.value;
state.height = resizeSensor2.$el.offsetHeight;
};
let columnsRef = ref([]);
function getItemIndex(vnode) {
const columnVNodes = columnsRef.value;
if (columnVNodes instanceof HTMLCollection) {
return Array.prototype.indexOf.call(columnVNodes, vnode.el);
}
return columnVNodes.indexOf(vnode);
}
const getPickerViewColumn = function(columnInstance) {
......@@ -10989,6 +11006,9 @@ var __publicField = (obj, key, value) => {
},
set(current) {
const index2 = getItemIndex(columnInstance.vnode);
if (index2 < 0) {
return;
}
const oldCurrent = state.value[index2];
if (oldCurrent !== current) {
state.value.splice(index2, 1, current);
......@@ -11005,9 +11025,14 @@ var __publicField = (obj, key, value) => {
provide("getPickerViewColumn", getPickerViewColumn);
provide("pickerViewProps", props2);
provide("pickerViewState", state);
{
useRebuild(() => {
onMountedCallback();
columnsRef.value = wrapperRef.value.children;
});
}
return () => {
const defaultSlots = slots.default && slots.default();
columnVNodes = flatVNode(defaultSlots);
return createVNode("uni-picker-view", {
"ref": rootRef
}, {
......@@ -11017,8 +11042,9 @@ var __publicField = (obj, key, value) => {
height
}) => state.height = height
}, null, 8, ["onResize"]), createVNode("div", {
"ref": wrapperRef,
"class": "uni-picker-view-wrapper"
}, [defaultSlots])],
}, [defaultSlots], 512)],
_: 2
}, 512);
};
......@@ -11757,10 +11783,10 @@ var __publicField = (obj, key, value) => {
const pickerViewState = inject("pickerViewState");
const indicatorHeight = ref(34);
const resizeSensorRef = ref(null);
onMounted(() => {
const resizeSensor = resizeSensorRef.value;
indicatorHeight.value = resizeSensor.$el.getBoundingClientRect().height;
});
const initIndicatorHeight = () => {
const resizeSensor2 = resizeSensorRef.value;
indicatorHeight.value = resizeSensor2.$el.offsetHeight;
};
const maskSize = computed$1(() => (pickerViewState.height - indicatorHeight.value) / 2);
const {
state: scopedAttrsState
......@@ -11771,9 +11797,12 @@ var __publicField = (obj, key, value) => {
current: currentRef.value,
length: 0
});
let updatesScrollerRequest;
function updatesScroller() {
if (scroller) {
if (scroller && !updatesScrollerRequest) {
updatesScrollerRequest = true;
nextTick(() => {
updatesScrollerRequest = false;
let current = Math.min(state.current, state.length - 1);
current = Math.max(current, 0);
scroller.update(current * indicatorHeight.value, void 0, indicatorHeight.value);
......@@ -11818,7 +11847,7 @@ var __publicField = (obj, key, value) => {
}
}
}
onMounted(() => {
const initScroller = () => {
const el = rootRef.value;
const content = contentRef.value;
const {
......@@ -11862,10 +11891,16 @@ var __publicField = (obj, key, value) => {
useCustomClick(el);
initScrollBounce();
updatesScroller();
});
};
{
useRebuild(() => {
state.length = contentRef.value.children.length;
initIndicatorHeight();
initScroller();
});
}
return () => {
const defaultSlots = slots.default && slots.default();
state.length = flatVNode(defaultSlots).length;
const padding = `${maskSize.value}px 0`;
return createVNode("uni-picker-view-column", {
"ref": rootRef
......@@ -13193,10 +13228,6 @@ var __publicField = (obj, key, value) => {
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
}
};
function useRebuild(callback) {
const instance = getCurrentInstance();
instance.rebuild = callback;
}
const props$5 = {
indicatorDots: {
type: [Boolean, String],
......@@ -14962,7 +14993,7 @@ var __publicField = (obj, key, value) => {
}
}
var movableArea = "uni-movable-area {\n display: block;\n position: relative;\n width: 10px;\n height: 10px;\n}\n\nuni-movable-area[hidden] {\n display: none;\n}\n";
class UniMovableArea extends UniComponent {
class UniMovableArea extends UniContainerComponent {
constructor(id2, parentNodeId, nodeJson) {
super(id2, "uni-movable-area", MovableArea, parentNodeId, nodeJson);
}
......@@ -14998,13 +15029,13 @@ var __publicField = (obj, key, value) => {
}
}
var pickerView = "uni-picker-view {\n display: block;\n}\n\n.uni-picker-view-wrapper {\n display: flex;\n position: relative;\n overflow: hidden;\n height: 100%;\n}\n\nuni-picker-view[hidden] {\n display: none;\n}\n";
class UniPickerView extends UniComponent {
class UniPickerView extends UniContainerComponent {
constructor(id2, parentNodeId, nodeJson) {
super(id2, "uni-picker-view", PickerView, parentNodeId, nodeJson, ".uni-picker-view-wrapper");
}
}
var pickerViewColumn = "uni-picker-view-column {\n flex: 1;\n position: relative;\n height: 100%;\n overflow: hidden;\n}\n\nuni-picker-view-column[hidden] {\n display: none;\n}\n\n.uni-picker-view-group {\n height: 100%;\n overflow: hidden;\n}\n\n.uni-picker-view-mask {\n transform: translateZ(0);\n}\n\n.uni-picker-view-indicator,\n.uni-picker-view-mask {\n position: absolute;\n left: 0;\n width: 100%;\n z-index: 3;\n pointer-events: none;\n}\n\n.uni-picker-view-mask {\n top: 0;\n height: 100%;\n margin: 0 auto;\n background: linear-gradient(\n 180deg,\n hsla(0, 0%, 100%, 0.95),\n hsla(0, 0%, 100%, 0.6)\n ),\n linear-gradient(0deg, hsla(0, 0%, 100%, 0.95), hsla(0, 0%, 100%, 0.6));\n background-position: top, bottom;\n background-size: 100% 102px;\n background-repeat: no-repeat;\n}\n\n.uni-picker-view-indicator {\n height: 34px;\n /* top: 102px; */\n top: 50%;\n transform: translateY(-50%);\n}\n\n.uni-picker-view-content {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n will-change: transform;\n padding: 102px 0;\n cursor: pointer;\n}\n\n.uni-picker-view-content > * {\n height: 34px;\n overflow: hidden;\n}\n\n.uni-picker-view-indicator:after,\n.uni-picker-view-indicator:before {\n content: ' ';\n position: absolute;\n left: 0;\n right: 0;\n height: 1px;\n color: #e5e5e5;\n}\n\n.uni-picker-view-indicator:before {\n top: 0;\n border-top: 1px solid #e5e5e5;\n transform-origin: 0 0;\n transform: scaleY(0.5);\n}\n\n.uni-picker-view-indicator:after {\n bottom: 0;\n border-bottom: 1px solid #e5e5e5;\n transform-origin: 0 100%;\n transform: scaleY(0.5);\n}\n\n.uni-picker-view-indicator:after,\n.uni-picker-view-indicator:before {\n content: ' ';\n position: absolute;\n left: 0;\n right: 0;\n height: 1px;\n color: #e5e5e5;\n}\n";
class UniPickerViewColumn extends UniComponent {
class UniPickerViewColumn extends UniContainerComponent {
constructor(id2, parentNodeId, nodeJson) {
super(id2, "uni-picker-view-column", PickerViewColumn, parentNodeId, nodeJson, ".uni-picker-view-content");
}
......
import '@dcloudio/uni-components/style/movable-area.css'
import { MovableArea } from '@dcloudio/uni-components'
import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent'
import { UniContainerComponent } from './UniComponent'
export class UniMovableArea extends UniComponent {
export class UniMovableArea extends UniContainerComponent {
constructor(
id: number,
parentNodeId: number,
......
import '@dcloudio/uni-components/style/picker-view.css'
import { PickerView } from '@dcloudio/uni-components'
import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent'
import { UniContainerComponent } from './UniComponent'
export class UniPickerView extends UniComponent {
export class UniPickerView extends UniContainerComponent {
constructor(
id: number,
parentNodeId: number,
......
import '@dcloudio/uni-components/style/picker-view-column.css'
import { PickerViewColumn } from '@dcloudio/uni-components'
import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent'
import { UniContainerComponent } from './UniComponent'
export class UniPickerViewColumn extends UniComponent {
export class UniPickerViewColumn extends UniContainerComponent {
constructor(
id: number,
parentNodeId: number,
......
......@@ -17,7 +17,6 @@ const plugins = [
mainJs_1.uniMainJsPlugin(),
manifestJson_1.uniManifestJsonPlugin(),
pagesJson_1.uniPagesJsonPlugin(),
uni_cli_shared_1.uniViteInjectPlugin(uni_cli_shared_1.initProvide()),
plugin_1.UniAppPlugin,
];
if (!process.env.UNI_APP_CODE_SPLITING) {
......
......@@ -14,6 +14,7 @@ import { useAttrs } from '../../helpers/useAttrs'
import { initScrollBounce, disableScrollBounce } from '../../helpers/scroll'
import ResizeSensor from '../resize-sensor/index'
import { flatVNode } from '../../helpers/flatVNode'
import { useRebuild } from '../../helpers/useRebuild'
const props = {
scaleArea: {
......@@ -37,7 +38,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
name: 'MovableArea',
props,
setup(props, { slots }) {
const rootRef = ref(null)
const rootRef: Ref<HTMLElement | null> = ref(null)
const _isMounted = ref(false)
let { setContexts, events: movableAreaEvents } = useMovableAreaState(
props,
......@@ -63,14 +64,17 @@ export default /*#__PURE__*/ defineBuiltInComponent({
_isMounted.value = true
})
let movableViewItems: VNode[] = []
let movableViewItems: VNode[] | HTMLCollection = []
const originMovableViewContexts: MovableViewContext[] = []
function updateMovableViewContexts() {
const contexts: MovableViewContext[] = []
for (let index = 0; index < movableViewItems.length; index++) {
const movableViewItem = movableViewItems[index]
let movableViewItem: VNode | Element = movableViewItems[index]
if (!(movableViewItem instanceof Element)) {
movableViewItem = movableViewItem.el as HTMLElement
}
const movableViewContext = originMovableViewContexts.find(
(context) => movableViewItem.el === context.rootRef.value
(context) => movableViewItem === context.rootRef.value
)
if (movableViewContext) {
contexts.push(markRaw(movableViewContext))
......@@ -78,6 +82,12 @@ export default /*#__PURE__*/ defineBuiltInComponent({
}
setContexts(contexts)
}
if (__PLATFORM__ === 'app') {
useRebuild(() => {
movableViewItems = (rootRef.value as HTMLElement).children
updateMovableViewContexts()
})
}
const addMovableViewContext: AddMovableViewContext = (
movableViewContext
) => {
......@@ -100,7 +110,9 @@ export default /*#__PURE__*/ defineBuiltInComponent({
return () => {
const defaultSlots = slots.default && slots.default()
movableViewItems = flatVNode(defaultSlots)
if (__PLATFORM__ !== 'app') {
movableViewItems = flatVNode(defaultSlots)
}
return (
<uni-movable-area
......
......@@ -20,6 +20,7 @@ import { initScrollBounce, disableScrollBounce } from '../../helpers/scroll'
import { useTouchtrack } from '../../helpers/useTouchtrack'
import { useScopedAttrs } from '../../helpers/useScopedAttrs'
import { flatVNode } from '../../helpers/flatVNode'
import { useRebuild } from '../../helpers/useRebuild'
import ResizeSensor from '../resize-sensor/index'
import {
GetPickerViewColumn,
......@@ -105,10 +106,13 @@ export default /*#__PURE__*/ defineBuiltInComponent({
const pickerViewState = inject('pickerViewState') as PickerViewState
const indicatorHeight = ref(34)
const resizeSensorRef: Ref<ComponentPublicInstance | null> = ref(null)
onMounted(() => {
const initIndicatorHeight = () => {
const resizeSensor = resizeSensorRef.value as ComponentPublicInstance
indicatorHeight.value = resizeSensor.$el.getBoundingClientRect().height
})
indicatorHeight.value = resizeSensor.$el.offsetHeight
}
if (__PLATFORM__ !== 'app') {
onMounted(initIndicatorHeight)
}
const maskSize = computed(
() => (pickerViewState.height - indicatorHeight.value) / 2
)
......@@ -122,9 +126,12 @@ export default /*#__PURE__*/ defineBuiltInComponent({
current: currentRef.value,
length: 0,
})
let updatesScrollerRequest: boolean
function updatesScroller() {
if (scroller) {
if (scroller && !updatesScrollerRequest) {
updatesScrollerRequest = true
nextTick(() => {
updatesScrollerRequest = false
let current = Math.min(state.current, state.length - 1)
current = Math.max(current, 0)
scroller.update(
......@@ -189,7 +196,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
}
}
onMounted(() => {
const initScroller = () => {
const el = rootRef.value as HTMLElement
const content = contentRef.value as HTMLElement
const {
......@@ -237,11 +244,25 @@ export default /*#__PURE__*/ defineBuiltInComponent({
useCustomClick(el)
initScrollBounce()
updatesScroller()
})
}
if (__PLATFORM__ !== 'app') {
onMounted(initScroller)
}
if (__PLATFORM__ === 'app') {
useRebuild(() => {
state.length = (contentRef.value as HTMLElement).children.length
// 由于 App 端 onMounted 时机未插入真实位置,需重新执行
initIndicatorHeight()
initScroller()
})
}
return () => {
const defaultSlots = slots.default && slots.default()
state.length = flatVNode(defaultSlots).length
if (__PLATFORM__ !== 'app') {
state.length = flatVNode(defaultSlots).length
}
const padding = `${maskSize.value}px 0`
return (
<uni-picker-view-column ref={rootRef}>
......
......@@ -15,6 +15,7 @@ import {
} from 'vue'
import { defineBuiltInComponent } from '../../helpers/component'
import { flatVNode } from '../../helpers/flatVNode'
import { useRebuild } from '../../helpers/useRebuild'
import ResizeSensor from '../resize-sensor/index'
import { useCustomEvent } from '../../helpers/useEvent'
......@@ -91,16 +92,27 @@ export default /*#__PURE__*/ defineBuiltInComponent({
emits: ['change', 'pickstart', 'pickend', 'update:value'],
setup(props, { slots, emit }) {
const rootRef: Ref<HTMLElement | null> = ref(null)
const wrapperRef: Ref<HTMLElement | null> = ref(null)
const trigger = useCustomEvent(rootRef, emit as SetupContext['emit'])
const state = useState(props)
const resizeSensorRef: Ref<ComponentPublicInstance | null> = ref(null)
onMounted(() => {
const onMountedCallback = () => {
const resizeSensor = resizeSensorRef.value as ComponentPublicInstance
state.height = resizeSensor.$el.getBoundingClientRect().height
})
let columnVNodes: VNode[] = []
state.height = resizeSensor.$el.offsetHeight
}
if (__PLATFORM__ !== 'app') {
onMounted(onMountedCallback)
}
let columnsRef: Ref<VNode[] | HTMLCollection> = ref([])
function getItemIndex(vnode: VNode): number {
return columnVNodes.indexOf(vnode)
const columnVNodes = columnsRef.value
if (columnVNodes instanceof HTMLCollection) {
return Array.prototype.indexOf.call(
columnVNodes as HTMLCollection,
vnode.el
)
}
return (columnVNodes as VNode[]).indexOf(vnode)
}
const getPickerViewColumn: GetPickerViewColumn = function (columnInstance) {
const ref: ComputedRef<number> = computed({
......@@ -110,6 +122,9 @@ export default /*#__PURE__*/ defineBuiltInComponent({
},
set(current: number) {
const index = getItemIndex(columnInstance.vnode)
if (index < 0) {
return
}
const oldCurrent = state.value[index]
if (oldCurrent !== current) {
state.value.splice(index, 1, current)
......@@ -128,10 +143,20 @@ export default /*#__PURE__*/ defineBuiltInComponent({
provide('pickerViewProps', props)
provide('pickerViewState', state)
if (__PLATFORM__ === 'app') {
useRebuild(() => {
// 由于 App 端 onMounted 时机未插入真实位置,需重新执行
onMountedCallback()
columnsRef.value = (wrapperRef.value as HTMLElement).children
})
}
return () => {
const defaultSlots = slots.default && slots.default()
// TODO filter
columnVNodes = flatVNode(defaultSlots)
if (__PLATFORM__ !== 'app') {
// TODO filter
columnsRef.value = flatVNode(defaultSlots)
}
return (
<uni-picker-view ref={rootRef}>
<ResizeSensor
......@@ -141,7 +166,9 @@ export default /*#__PURE__*/ defineBuiltInComponent({
(state.height = height)
}
></ResizeSensor>
<div class="uni-picker-view-wrapper">{defaultSlots}</div>
<div ref={wrapperRef} class="uni-picker-view-wrapper">
{defaultSlots}
</div>
</uni-picker-view>
)
}
......
......@@ -2530,8 +2530,7 @@ function useQuill(props2, rootRef, trigger) {
});
vue.watch(() => props2.placeholder, (value) => {
});
const id = useContextInfo();
useSubscribe((type, data) => {
registerViewMethod(getCurrentPageId(), `editor.${props2.id}`, ({ type, data }, resolve) => {
const { options, callbackId } = data;
let res;
let errMsg;
......@@ -2539,14 +2538,14 @@ function useQuill(props2, rootRef, trigger) {
errMsg = "not ready";
}
if (callbackId) {
UniViewJSBridge.publishHandler("onEditorMethodCallback", {
resolve({
callbackId,
data: shared.extend({}, res, {
errMsg: `${type}:${errMsg ? "fail " + errMsg : "ok"}`
})
});
}
}, id, true);
});
}
const props$q = /* @__PURE__ */ shared.extend({}, props$r, {
id: {
......@@ -3411,8 +3410,11 @@ var index$p = /* @__PURE__ */ defineBuiltInComponent({
function updateMovableViewContexts() {
const contexts = [];
for (let index2 = 0; index2 < movableViewItems.length; index2++) {
const movableViewItem = movableViewItems[index2];
const movableViewContext = originMovableViewContexts.find((context) => movableViewItem.el === context.rootRef.value);
let movableViewItem = movableViewItems[index2];
if (!(movableViewItem instanceof Element)) {
movableViewItem = movableViewItem.el;
}
const movableViewContext = originMovableViewContexts.find((context) => movableViewItem === context.rootRef.value);
if (movableViewContext) {
contexts.push(vue.markRaw(movableViewContext));
}
......@@ -3436,7 +3438,9 @@ var index$p = /* @__PURE__ */ defineBuiltInComponent({
vue.provide("removeMovableViewContext", removeMovableViewContext);
return () => {
const defaultSlots = slots.default && slots.default();
movableViewItems = flatVNode(defaultSlots);
{
movableViewItems = flatVNode(defaultSlots);
}
return vue.createVNode("uni-movable-area", vue.mergeProps({
"ref": rootRef
}, $attrs.value, $excludeAttrs.value, _listeners), {
......@@ -4454,11 +4458,16 @@ var PickerView = /* @__PURE__ */ defineBuiltInComponent({
emit: emit2
}) {
const rootRef = vue.ref(null);
const wrapperRef = vue.ref(null);
const trigger = useCustomEvent(rootRef, emit2);
const state = useState$2(props2);
const resizeSensorRef = vue.ref(null);
let columnVNodes = [];
let columnsRef = vue.ref([]);
function getItemIndex(vnode) {
const columnVNodes = columnsRef.value;
if (columnVNodes instanceof HTMLCollection) {
return Array.prototype.indexOf.call(columnVNodes, vnode.el);
}
return columnVNodes.indexOf(vnode);
}
const getPickerViewColumn = function(columnInstance) {
......@@ -4469,6 +4478,9 @@ var PickerView = /* @__PURE__ */ defineBuiltInComponent({
},
set(current) {
const index2 = getItemIndex(columnInstance.vnode);
if (index2 < 0) {
return;
}
const oldCurrent = state.value[index2];
if (oldCurrent !== current) {
state.value.splice(index2, 1, current);
......@@ -4487,7 +4499,9 @@ var PickerView = /* @__PURE__ */ defineBuiltInComponent({
vue.provide("pickerViewState", state);
return () => {
const defaultSlots = slots.default && slots.default();
columnVNodes = flatVNode(defaultSlots);
{
columnsRef.value = flatVNode(defaultSlots);
}
return vue.createVNode("uni-picker-view", {
"ref": rootRef
}, {
......@@ -4497,8 +4511,9 @@ var PickerView = /* @__PURE__ */ defineBuiltInComponent({
height
}) => state.height = height
}, null, 8, ["onResize"]), vue.createVNode("div", {
"ref": wrapperRef,
"class": "uni-picker-view-wrapper"
}, [defaultSlots])],
}, [defaultSlots], 512)],
_: 2
}, 512);
};
......@@ -4581,7 +4596,9 @@ var PickerViewColumn = /* @__PURE__ */ defineBuiltInComponent({
}
return () => {
const defaultSlots = slots.default && slots.default();
state.length = flatVNode(defaultSlots).length;
{
state.length = flatVNode(defaultSlots).length;
}
const padding = `${maskSize.value}px 0`;
return vue.createVNode("uni-picker-view-column", {
"ref": rootRef
......
......@@ -4007,28 +4007,24 @@ const createMediaQueryObserver = /* @__PURE__ */ defineSyncApi("createMediaQuery
}
return new ServiceMediaQueryObserver(getCurrentPageVm());
});
let eventReady = false;
let index$r = 0;
let optionsCache = {};
function operateEditor(componentId, pageId, type, options) {
const data = {};
if (options && ("success" in options || "fail" in options || "complete" in options)) {
const data = { options };
const needCallOptions = options && ("success" in options || "fail" in options || "complete" in options);
if (needCallOptions) {
const callbackId = String(index$r++);
data.callbackId = callbackId;
optionsCache[callbackId] = options;
if (!eventReady) {
UniServiceJSBridge.subscribe("onEditorMethodCallback", ({ callbackId: callbackId2, data: data2 }) => {
callOptions(optionsCache[callbackId2], data2);
delete optionsCache[callbackId2];
});
eventReady = true;
}
}
data.options = options;
UniServiceJSBridge.publishHandler("editor." + componentId, {
componentId,
UniServiceJSBridge.invokeViewMethod(`editor.${componentId}`, {
type,
data
}, ({ callbackId, data: data2 }) => {
if (needCallOptions) {
callOptions(optionsCache[callbackId], data2);
delete optionsCache[callbackId];
}
}, pageId);
}
class EditorContext {
......@@ -7388,8 +7384,7 @@ function useQuill(props2, rootRef, trigger) {
}
});
});
const id2 = useContextInfo();
useSubscribe((type, data) => {
registerViewMethod(getCurrentPageId(), `editor.${props2.id}`, ({ type, data }, resolve) => {
const { options, callbackId } = data;
let res;
let range;
......@@ -7526,14 +7521,14 @@ function useQuill(props2, rootRef, trigger) {
errMsg = "not ready";
}
if (callbackId) {
UniViewJSBridge.publishHandler("onEditorMethodCallback", {
resolve({
callbackId,
data: extend({}, res, {
errMsg: `${type}:${errMsg ? "fail " + errMsg : "ok"}`
})
});
}
}, id2, true);
});
}
const props$x = /* @__PURE__ */ extend({}, props$y, {
id: {
......@@ -8479,8 +8474,11 @@ var MovableArea = /* @__PURE__ */ defineBuiltInComponent({
function updateMovableViewContexts() {
const contexts = [];
for (let index2 = 0; index2 < movableViewItems.length; index2++) {
const movableViewItem = movableViewItems[index2];
const movableViewContext = originMovableViewContexts.find((context) => movableViewItem.el === context.rootRef.value);
let movableViewItem = movableViewItems[index2];
if (!(movableViewItem instanceof Element)) {
movableViewItem = movableViewItem.el;
}
const movableViewContext = originMovableViewContexts.find((context) => movableViewItem === context.rootRef.value);
if (movableViewContext) {
contexts.push(markRaw(movableViewContext));
}
......@@ -8504,7 +8502,9 @@ var MovableArea = /* @__PURE__ */ defineBuiltInComponent({
provide("removeMovableViewContext", removeMovableViewContext);
return () => {
const defaultSlots = slots.default && slots.default();
movableViewItems = flatVNode(defaultSlots);
{
movableViewItems = flatVNode(defaultSlots);
}
return createVNode("uni-movable-area", mergeProps({
"ref": rootRef
}, $attrs.value, $excludeAttrs.value, _listeners), {
......@@ -9847,15 +9847,23 @@ var PickerView = /* @__PURE__ */ defineBuiltInComponent({
emit: emit2
}) {
const rootRef = ref(null);
const wrapperRef = ref(null);
const trigger = useCustomEvent(rootRef, emit2);
const state2 = useState$3(props2);
const resizeSensorRef = ref(null);
onMounted(() => {
const onMountedCallback = () => {
const resizeSensor = resizeSensorRef.value;
state2.height = resizeSensor.$el.getBoundingClientRect().height;
});
let columnVNodes = [];
state2.height = resizeSensor.$el.offsetHeight;
};
{
onMounted(onMountedCallback);
}
let columnsRef = ref([]);
function getItemIndex(vnode) {
const columnVNodes = columnsRef.value;
if (columnVNodes instanceof HTMLCollection) {
return Array.prototype.indexOf.call(columnVNodes, vnode.el);
}
return columnVNodes.indexOf(vnode);
}
const getPickerViewColumn = function(columnInstance) {
......@@ -9866,6 +9874,9 @@ var PickerView = /* @__PURE__ */ defineBuiltInComponent({
},
set(current) {
const index2 = getItemIndex(columnInstance.vnode);
if (index2 < 0) {
return;
}
const oldCurrent = state2.value[index2];
if (oldCurrent !== current) {
state2.value.splice(index2, 1, current);
......@@ -9884,7 +9895,9 @@ var PickerView = /* @__PURE__ */ defineBuiltInComponent({
provide("pickerViewState", state2);
return () => {
const defaultSlots = slots.default && slots.default();
columnVNodes = flatVNode(defaultSlots);
{
columnsRef.value = flatVNode(defaultSlots);
}
return createVNode("uni-picker-view", {
"ref": rootRef
}, {
......@@ -9894,8 +9907,9 @@ var PickerView = /* @__PURE__ */ defineBuiltInComponent({
height
}) => state2.height = height
}, null, 8, ["onResize"]), createVNode("div", {
"ref": wrapperRef,
"class": "uni-picker-view-wrapper"
}, [defaultSlots])],
}, [defaultSlots], 512)],
_: 2
}, 512);
};
......@@ -10634,10 +10648,13 @@ var PickerViewColumn = /* @__PURE__ */ defineBuiltInComponent({
const pickerViewState = inject("pickerViewState");
const indicatorHeight = ref(34);
const resizeSensorRef = ref(null);
onMounted(() => {
const initIndicatorHeight = () => {
const resizeSensor = resizeSensorRef.value;
indicatorHeight.value = resizeSensor.$el.getBoundingClientRect().height;
});
indicatorHeight.value = resizeSensor.$el.offsetHeight;
};
{
onMounted(initIndicatorHeight);
}
const maskSize = computed(() => (pickerViewState.height - indicatorHeight.value) / 2);
const {
state: scopedAttrsState
......@@ -10648,9 +10665,12 @@ var PickerViewColumn = /* @__PURE__ */ defineBuiltInComponent({
current: currentRef.value,
length: 0
});
let updatesScrollerRequest;
function updatesScroller() {
if (scroller) {
if (scroller && !updatesScrollerRequest) {
updatesScrollerRequest = true;
nextTick(() => {
updatesScrollerRequest = false;
let current = Math.min(state2.current, state2.length - 1);
current = Math.max(current, 0);
scroller.update(current * indicatorHeight.value, void 0, indicatorHeight.value);
......@@ -10695,7 +10715,7 @@ var PickerViewColumn = /* @__PURE__ */ defineBuiltInComponent({
}
}
}
onMounted(() => {
const initScroller = () => {
const el = rootRef.value;
const content = contentRef.value;
const {
......@@ -10732,10 +10752,15 @@ var PickerViewColumn = /* @__PURE__ */ defineBuiltInComponent({
}, true);
useCustomClick(el);
updatesScroller();
});
};
{
onMounted(initScroller);
}
return () => {
const defaultSlots = slots.default && slots.default();
state2.length = flatVNode(defaultSlots).length;
{
state2.length = flatVNode(defaultSlots).length;
}
const padding = `${maskSize.value}px 0`;
return createVNode("uni-picker-view-column", {
"ref": rootRef
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册