x-runtime-lib 0.8.201 → 0.8.202
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +26 -3
- package/dist/types/data.d.ts +4 -11
- package/dist/utils/reactivity.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10313,12 +10313,35 @@ function unwrapTriggerId(e) {
|
|
|
10313
10313
|
triggerKey: p[1]
|
|
10314
10314
|
};
|
|
10315
10315
|
}
|
|
10316
|
+
async function initReactivity(e, p) {
|
|
10317
|
+
await initWatchEffect(e, p), await initBind(e, p);
|
|
10318
|
+
}
|
|
10319
|
+
async function initWatchEffect(e, p) {
|
|
10320
|
+
let { watchEffect: m } = p;
|
|
10321
|
+
for (let p of m.ids) {
|
|
10322
|
+
let m = encodeString(p);
|
|
10323
|
+
await e.callFunctionAsync(`__watchEffect$${m}__`);
|
|
10324
|
+
}
|
|
10325
|
+
}
|
|
10326
|
+
async function initBind(e, p) {
|
|
10327
|
+
let { bind: m } = p;
|
|
10328
|
+
for (let p in m.sets) {
|
|
10329
|
+
let g = m.sets[p];
|
|
10330
|
+
if (g.length < 2) continue;
|
|
10331
|
+
let _, { kind: v, triggerKey: y } = unwrapTriggerId(g[0]);
|
|
10332
|
+
v === "propertyTrigger" ? _ = await e.getProperty(y) : v === "stateTrigger" ? _ = await e.getState(y) : console.assert(!1);
|
|
10333
|
+
for (let p of g) {
|
|
10334
|
+
let { kind: m, triggerKey: g } = unwrapTriggerId(p);
|
|
10335
|
+
m === "propertyTrigger" ? await e.setProperty(g, _) : m === "stateTrigger" ? await e.setState(g, _) : console.assert(!1);
|
|
10336
|
+
}
|
|
10337
|
+
}
|
|
10338
|
+
}
|
|
10316
10339
|
async function triggerReactivity(e, p, m, g, _) {
|
|
10317
10340
|
await triggerWatchEffect(e, p, m), await triggerBind(e, p, m, g, _);
|
|
10318
10341
|
}
|
|
10319
10342
|
async function triggerWatchEffect(e, p, m) {
|
|
10320
10343
|
let { watchEffect: g } = p;
|
|
10321
|
-
if (g[m]) for (let p of g[m]) {
|
|
10344
|
+
if (g.triggers[m]) for (let p of g.triggers[m]) {
|
|
10322
10345
|
let m = encodeString(p);
|
|
10323
10346
|
await e.callFunctionAsync(`__watchEffect$${m}__`);
|
|
10324
10347
|
}
|
|
@@ -10663,7 +10686,7 @@ var PromiseManager = class {
|
|
|
10663
10686
|
return this.data.value?.view.nodes[e];
|
|
10664
10687
|
}
|
|
10665
10688
|
async createVm(e, p) {
|
|
10666
|
-
this.vm = e.newContext(), this.promiseManager = new PromiseManager(this.vm), bind(this), this.vm.evalCode("\nlet __events__ = {}\n\nfunction __onEventV1__(id, callback) {\n if (typeof(id) !== 'string' || !id) {\n return\n }\n if (typeof(callback) !== 'function') {\n return\n }\n if (!__events__[id]) {\n __events__[id] = []\n }\n const callbacks = __events__[id]\n for (let i = 0; i < callbacks.length; i++) {\n if (callbacks[i] === callback) {\n return\n }\n }\n callbacks.push(callback)\n}\n\nasync function __triggerEventInner__(id, params, instance) {\n if (!__events__[id]) {\n return\n }\n const callbacks = __events__[id]\n if (!callbacks) {\n return\n }\n for (let i = 0; i < callbacks.length; i++) {\n await callbacks[i](params, instance)\n }\n}\n\nlet __timers__ = {}\nlet __currTimerId__ = 0\n\nfunction __createTimerV1__(interval, loop, count, immediate, callback) {\n if (!loop && count <= 0) {\n return\n }\n const timer = {}\n timer.id = __currTimerId__++\n timer.interval = interval\n timer.loop = loop\n timer.count = count\n timer.immediate = immediate\n timer.callback = callback\n __timers__[timer.id] = timer\n if (timer.immediate) {\n __timeoutCallbackV1__(timer.id)\n } else {\n __timeoutV1__(timer.id, timer.interval)\n }\n}\n\nasync function __timeoutCallback__(timerId) {\n const timer = __timers__[timerId]\n if (timer) {\n timer.callback()\n // 修改计数\n if (!timer.loop) {\n timer.count = timer.count - 1\n }\n // 触发超时\n if (timer.loop || timer.count > 0) {\n await __timeoutV1__(timer.id, timer.interval)\n }\n // 回收\n if (!timer.loop && timer.count <= 0) {\n delete __timers__[timer.id]\n }\n }\n}\n\nfunction __destroy__() {\n __events__ = {}\n __timers__ = {}\n}\n"), this.setGlobalVariable("__env__", this.env), this.vm.evalCode(p), await nextTick(), this.hooks.onReady();
|
|
10689
|
+
this.vm = e.newContext(), this.promiseManager = new PromiseManager(this.vm), bind(this), this.vm.evalCode("\nlet __events__ = {}\n\nfunction __onEventV1__(id, callback) {\n if (typeof(id) !== 'string' || !id) {\n return\n }\n if (typeof(callback) !== 'function') {\n return\n }\n if (!__events__[id]) {\n __events__[id] = []\n }\n const callbacks = __events__[id]\n for (let i = 0; i < callbacks.length; i++) {\n if (callbacks[i] === callback) {\n return\n }\n }\n callbacks.push(callback)\n}\n\nasync function __triggerEventInner__(id, params, instance) {\n if (!__events__[id]) {\n return\n }\n const callbacks = __events__[id]\n if (!callbacks) {\n return\n }\n for (let i = 0; i < callbacks.length; i++) {\n await callbacks[i](params, instance)\n }\n}\n\nlet __timers__ = {}\nlet __currTimerId__ = 0\n\nfunction __createTimerV1__(interval, loop, count, immediate, callback) {\n if (!loop && count <= 0) {\n return\n }\n const timer = {}\n timer.id = __currTimerId__++\n timer.interval = interval\n timer.loop = loop\n timer.count = count\n timer.immediate = immediate\n timer.callback = callback\n __timers__[timer.id] = timer\n if (timer.immediate) {\n __timeoutCallbackV1__(timer.id)\n } else {\n __timeoutV1__(timer.id, timer.interval)\n }\n}\n\nasync function __timeoutCallback__(timerId) {\n const timer = __timers__[timerId]\n if (timer) {\n timer.callback()\n // 修改计数\n if (!timer.loop) {\n timer.count = timer.count - 1\n }\n // 触发超时\n if (timer.loop || timer.count > 0) {\n await __timeoutV1__(timer.id, timer.interval)\n }\n // 回收\n if (!timer.loop && timer.count <= 0) {\n delete __timers__[timer.id]\n }\n }\n}\n\nfunction __destroy__() {\n __events__ = {}\n __timers__ = {}\n}\n"), this.setGlobalVariable("__env__", this.env), this.vm.evalCode(p), this.data.value?.code.reactivity && await initReactivity(this, this.data.value?.code.reactivity), await nextTick(), this.hooks.onReady();
|
|
10667
10690
|
}
|
|
10668
10691
|
destroyVm() {
|
|
10669
10692
|
this.vm && this.hooks.onDestroy(), this.promiseManager &&= (this.promiseManager.dispose(), void 0), this.vm &&= (this.vm.dispose(), void 0);
|
|
@@ -11195,4 +11218,4 @@ async function loadLocaleMessageRuntime(e) {
|
|
|
11195
11218
|
"./locales/zhHans/index.ts": () => import("./zhHans.gwvwcjmv.js")
|
|
11196
11219
|
}, `./locales/${e}/index.ts`, 4)).default;
|
|
11197
11220
|
}
|
|
11198
|
-
export { addIndent, ambientLightV1, badgeV1, barChartV1, boxGeometryV1, breakpoints, btnGroupV1, btnToggleV1, btnV1, calcBreakpoint, cardV1, checkboxV1, chipGroupV1, chipV1, colorPickerV1, comboboxV1, compTypes, containerV1, dataStringify, dataTableV1, datePickerV1, dialogV1, directionalLightV1, duplicateNodePair, duplicateNodePairs, elementKeys, fileInputV1, finalProperties, flexLayoutEntryV1, flexLayoutV1, formV1, fromDotString, genId, getAllElements, getBreakpointProp, getElement, getElementMust, getField, getImplementMethodName, getIndexOfBreakpoint, getNodeLite, getProperties, getPropertyDefault, getTag, globalityV1, groupV1, hasComp, hasSlot, iconV1, initNode, initProperties, injectDark, injectData, injectDepends, injectDevice, injectEnv, injectId, injectMeta, injectMode, injectNode, injectOrg, injectRuntime, injectSandbox, injectType, isCircularReference, isExecutableMode, isPercentStr, isPixelStr, keyboardControlsV1, lineChartV1, loadLocaleMessageRuntime, makeEventId, makeEventKeyOfCustomSlot, makeEventKeyOfElementSlot, makeMethodId, makeMethodKeyOfCustomSlot, makeMethodKeyOfElementSlot, makePropertyId, makePropertyKeyOfCustomSlot, makePropertyKeyOfElementSlot, makeSlotId, makeTriggerId, mapControlsV1, menuV1, meshBasicMaterialV1, meshV1, metaStringify, multipleRefV1, multipleSlotV1, numberInputV1, orbitControlsV1, orthographicCameraV1, pageTypes, paginationV1, parseData, parseMeta, parsePercentStr, parsePixelStr, perspectiveCameraV1, pkgs, pointLightV1, provideDark, provideData, provideDepends, provideDevice, provideEnv, provideId, provideMeta, provideMode, provideNode, provideOrg, provideRuntime, provideSandbox, provideType, radioGroupV1, radioV1, rangeSliderV1, ratingV1, referenceV1, regElement, renderSwitchV1, reverseBreakpoints, selectV1, setField, sliderV1, slotV1, spawnNode, sphereGeometryV1, spotLightV1, stepperHeaderV1, stepperItemV1, stepperV1, stepperWindowItemV1, stepperWindowV1, switchV1, tabV1, tabsV1, textFieldV1, textV1, textareaV1, timelineItemV1, timelineV1, toDotString, toEventName, toMethodName, toNodeLite, toPropertyName, triggerReactivity, unwrapEventId, unwrapEventKeyOfCustomSlot, unwrapEventKeyOfElementSlot, unwrapMethodId, unwrapMethodKeyOfCustomSlot, unwrapMethodKeyOfElementSlot, unwrapPropertyId, unwrapPropertyKeyOfCustomSlot, unwrapPropertyKeyOfElementSlot, unwrapSlotId, unwrapTriggerId, useDepend, useRuntime, useSandbox, useTheme, windowItemV1, windowV1 };
|
|
11221
|
+
export { addIndent, ambientLightV1, badgeV1, barChartV1, boxGeometryV1, breakpoints, btnGroupV1, btnToggleV1, btnV1, calcBreakpoint, cardV1, checkboxV1, chipGroupV1, chipV1, colorPickerV1, comboboxV1, compTypes, containerV1, dataStringify, dataTableV1, datePickerV1, dialogV1, directionalLightV1, duplicateNodePair, duplicateNodePairs, elementKeys, fileInputV1, finalProperties, flexLayoutEntryV1, flexLayoutV1, formV1, fromDotString, genId, getAllElements, getBreakpointProp, getElement, getElementMust, getField, getImplementMethodName, getIndexOfBreakpoint, getNodeLite, getProperties, getPropertyDefault, getTag, globalityV1, groupV1, hasComp, hasSlot, iconV1, initNode, initProperties, initReactivity, injectDark, injectData, injectDepends, injectDevice, injectEnv, injectId, injectMeta, injectMode, injectNode, injectOrg, injectRuntime, injectSandbox, injectType, isCircularReference, isExecutableMode, isPercentStr, isPixelStr, keyboardControlsV1, lineChartV1, loadLocaleMessageRuntime, makeEventId, makeEventKeyOfCustomSlot, makeEventKeyOfElementSlot, makeMethodId, makeMethodKeyOfCustomSlot, makeMethodKeyOfElementSlot, makePropertyId, makePropertyKeyOfCustomSlot, makePropertyKeyOfElementSlot, makeSlotId, makeTriggerId, mapControlsV1, menuV1, meshBasicMaterialV1, meshV1, metaStringify, multipleRefV1, multipleSlotV1, numberInputV1, orbitControlsV1, orthographicCameraV1, pageTypes, paginationV1, parseData, parseMeta, parsePercentStr, parsePixelStr, perspectiveCameraV1, pkgs, pointLightV1, provideDark, provideData, provideDepends, provideDevice, provideEnv, provideId, provideMeta, provideMode, provideNode, provideOrg, provideRuntime, provideSandbox, provideType, radioGroupV1, radioV1, rangeSliderV1, ratingV1, referenceV1, regElement, renderSwitchV1, reverseBreakpoints, selectV1, setField, sliderV1, slotV1, spawnNode, sphereGeometryV1, spotLightV1, stepperHeaderV1, stepperItemV1, stepperV1, stepperWindowItemV1, stepperWindowV1, switchV1, tabV1, tabsV1, textFieldV1, textV1, textareaV1, timelineItemV1, timelineV1, toDotString, toEventName, toMethodName, toNodeLite, toPropertyName, triggerReactivity, unwrapEventId, unwrapEventKeyOfCustomSlot, unwrapEventKeyOfElementSlot, unwrapMethodId, unwrapMethodKeyOfCustomSlot, unwrapMethodKeyOfElementSlot, unwrapPropertyId, unwrapPropertyKeyOfCustomSlot, unwrapPropertyKeyOfElementSlot, unwrapSlotId, unwrapTriggerId, useDepend, useRuntime, useSandbox, useTheme, windowItemV1, windowV1 };
|
package/dist/types/data.d.ts
CHANGED
|
@@ -29,18 +29,12 @@ export interface View {
|
|
|
29
29
|
[key: string]: Node;
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
interface TriggerProperty {
|
|
33
|
-
type: 'property';
|
|
34
|
-
propertyId: string;
|
|
35
|
-
}
|
|
36
|
-
interface TriggerState {
|
|
37
|
-
type: 'state';
|
|
38
|
-
stateId: string;
|
|
39
|
-
}
|
|
40
|
-
export type Trigger = TriggerProperty | TriggerState;
|
|
41
32
|
export interface Reactivity {
|
|
42
33
|
watchEffect: {
|
|
43
|
-
|
|
34
|
+
ids: string[];
|
|
35
|
+
triggers: {
|
|
36
|
+
[key: string]: string[];
|
|
37
|
+
};
|
|
44
38
|
};
|
|
45
39
|
bind: {
|
|
46
40
|
sets: {
|
|
@@ -64,4 +58,3 @@ export interface Data {
|
|
|
64
58
|
}
|
|
65
59
|
export declare function dataStringify({ type, version, view, code }: Data): string;
|
|
66
60
|
export declare function parseData(str: string): Data;
|
|
67
|
-
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Sandbox } from '@/sandbox';
|
|
2
2
|
import { Reactivity } from '@/types';
|
|
3
|
+
export declare function initReactivity(sandbox: Sandbox, reactivity: Reactivity): Promise<void>;
|
|
3
4
|
export declare function triggerReactivity(sandbox: Sandbox, reactivity: Reactivity, triggerId: string, newValue: any, oldValue: any): Promise<void>;
|