@vortexm/vjt 0.1.15 → 0.1.16
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 +374 -29
- package/dist/lib/network.d.ts +5 -2
- package/dist/lib/types.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3865,7 +3865,7 @@ var NetworkRuntime = class {
|
|
|
3865
3865
|
this.rerenderRoot = options.rerenderRoot;
|
|
3866
3866
|
}
|
|
3867
3867
|
connectSseStreams() {
|
|
3868
|
-
if (typeof window === "undefined" ||
|
|
3868
|
+
if (typeof window === "undefined" || this.eventSources.length > 0) {
|
|
3869
3869
|
return;
|
|
3870
3870
|
}
|
|
3871
3871
|
for (const config of this.sseConfigs) {
|
|
@@ -3877,26 +3877,10 @@ var NetworkRuntime = class {
|
|
|
3877
3877
|
logRuntimeError("sseConfig", new Error("Blocked unsafe SSE url"), { url: config.url });
|
|
3878
3878
|
continue;
|
|
3879
3879
|
}
|
|
3880
|
-
const
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
if (!eventDefinition?.name) {
|
|
3884
|
-
continue;
|
|
3885
|
-
}
|
|
3886
|
-
source.addEventListener(eventDefinition.name, (event) => {
|
|
3887
|
-
void this.handleSseEvent(eventDefinition, event).catch((error) => {
|
|
3888
|
-
logRuntimeError("handleSseEvent", error, {
|
|
3889
|
-
eventName: eventDefinition.name,
|
|
3890
|
-
url: safeUrl
|
|
3891
|
-
});
|
|
3892
|
-
});
|
|
3893
|
-
});
|
|
3880
|
+
const connection = this.createSseConnection(config, safeUrl);
|
|
3881
|
+
if (connection) {
|
|
3882
|
+
this.eventSources.push(connection);
|
|
3894
3883
|
}
|
|
3895
|
-
source.onerror = (event) => {
|
|
3896
|
-
logRuntimeError("sseConnection", event, {
|
|
3897
|
-
url: config.url
|
|
3898
|
-
});
|
|
3899
|
-
};
|
|
3900
3884
|
}
|
|
3901
3885
|
}
|
|
3902
3886
|
async executeRequest(requestName, currentValue) {
|
|
@@ -4099,21 +4083,297 @@ var NetworkRuntime = class {
|
|
|
4099
4083
|
return this.stringifyPrimitive(value);
|
|
4100
4084
|
}
|
|
4101
4085
|
}
|
|
4102
|
-
|
|
4086
|
+
createSseConnection(config, safeUrl) {
|
|
4087
|
+
if (typeof fetch === "function" && typeof AbortController !== "undefined" && typeof TextDecoder !== "undefined" && typeof ReadableStream !== "undefined") {
|
|
4088
|
+
return this.createFetchSseConnection(config, safeUrl);
|
|
4089
|
+
}
|
|
4090
|
+
if (typeof EventSource !== "undefined") {
|
|
4091
|
+
return this.createNativeSseConnection(config, safeUrl);
|
|
4092
|
+
}
|
|
4093
|
+
logRuntimeError("sseConnection", new Error("SSE is not supported in this browser"), {
|
|
4094
|
+
url: safeUrl
|
|
4095
|
+
});
|
|
4096
|
+
return null;
|
|
4097
|
+
}
|
|
4098
|
+
createNativeSseConnection(config, safeUrl) {
|
|
4099
|
+
const source = new EventSource(safeUrl);
|
|
4100
|
+
source.onopen = () => {
|
|
4101
|
+
logRuntimeDebug(this.debugLogging, "sse-open", {
|
|
4102
|
+
url: safeUrl,
|
|
4103
|
+
transport: "event-source"
|
|
4104
|
+
});
|
|
4105
|
+
};
|
|
4106
|
+
source.onmessage = (event) => {
|
|
4107
|
+
const payload = typeof event.data === "string" ? event.data : "";
|
|
4108
|
+
logRuntimeDebug(this.debugLogging, "sse-message", {
|
|
4109
|
+
url: safeUrl,
|
|
4110
|
+
transport: "event-source",
|
|
4111
|
+
eventName: "message",
|
|
4112
|
+
payloadLength: payload.length
|
|
4113
|
+
});
|
|
4114
|
+
};
|
|
4115
|
+
for (const eventDefinition of config.events ?? []) {
|
|
4116
|
+
if (!eventDefinition?.name) {
|
|
4117
|
+
continue;
|
|
4118
|
+
}
|
|
4119
|
+
source.addEventListener(eventDefinition.name, (event) => {
|
|
4120
|
+
void this.handleSseEvent(eventDefinition, event.data ?? "", safeUrl).catch((error) => {
|
|
4121
|
+
logRuntimeError("handleSseEvent", error, {
|
|
4122
|
+
eventName: eventDefinition.name,
|
|
4123
|
+
url: safeUrl
|
|
4124
|
+
});
|
|
4125
|
+
});
|
|
4126
|
+
});
|
|
4127
|
+
}
|
|
4128
|
+
source.onerror = (event) => {
|
|
4129
|
+
logRuntimeError("sseConnection", event, {
|
|
4130
|
+
url: config.url,
|
|
4131
|
+
transport: "event-source"
|
|
4132
|
+
});
|
|
4133
|
+
};
|
|
4134
|
+
logRuntimeDebug(this.debugLogging, "sse-connect", {
|
|
4135
|
+
url: safeUrl,
|
|
4136
|
+
transport: "event-source"
|
|
4137
|
+
});
|
|
4138
|
+
return {
|
|
4139
|
+
close: () => {
|
|
4140
|
+
source.close();
|
|
4141
|
+
}
|
|
4142
|
+
};
|
|
4143
|
+
}
|
|
4144
|
+
createFetchSseConnection(config, safeUrl) {
|
|
4145
|
+
let closed = false;
|
|
4146
|
+
let reconnectDelayMs = 2e3;
|
|
4147
|
+
let reconnectTimeoutId = null;
|
|
4148
|
+
let activeAbortController = null;
|
|
4149
|
+
let lastEventId = "";
|
|
4150
|
+
let connectionAttempt = 0;
|
|
4151
|
+
const clearReconnectTimeout = () => {
|
|
4152
|
+
if (reconnectTimeoutId !== null && typeof window !== "undefined") {
|
|
4153
|
+
window.clearTimeout(reconnectTimeoutId);
|
|
4154
|
+
}
|
|
4155
|
+
reconnectTimeoutId = null;
|
|
4156
|
+
};
|
|
4157
|
+
const scheduleReconnect = (reason) => {
|
|
4158
|
+
if (closed || typeof window === "undefined") {
|
|
4159
|
+
return;
|
|
4160
|
+
}
|
|
4161
|
+
logRuntimeDebug(this.debugLogging, "sse-reconnect-scheduled", {
|
|
4162
|
+
url: safeUrl,
|
|
4163
|
+
transport: "fetch",
|
|
4164
|
+
delayMs: reconnectDelayMs,
|
|
4165
|
+
reason,
|
|
4166
|
+
lastEventId
|
|
4167
|
+
});
|
|
4168
|
+
clearReconnectTimeout();
|
|
4169
|
+
reconnectTimeoutId = window.setTimeout(() => {
|
|
4170
|
+
reconnectTimeoutId = null;
|
|
4171
|
+
void connectLoop().catch((error) => {
|
|
4172
|
+
logRuntimeError("sseConnection", error, {
|
|
4173
|
+
url: safeUrl,
|
|
4174
|
+
transport: "fetch"
|
|
4175
|
+
});
|
|
4176
|
+
});
|
|
4177
|
+
}, reconnectDelayMs);
|
|
4178
|
+
};
|
|
4179
|
+
const flushSseChunk = (eventName, dataLines) => {
|
|
4180
|
+
if (!dataLines.length) {
|
|
4181
|
+
return;
|
|
4182
|
+
}
|
|
4183
|
+
const payload = dataLines.join("\n");
|
|
4184
|
+
const matchingDefinitions = (config.events ?? []).filter((definition) => definition?.name === eventName);
|
|
4185
|
+
logRuntimeDebug(this.debugLogging, "sse-dispatch", {
|
|
4186
|
+
url: safeUrl,
|
|
4187
|
+
transport: "fetch",
|
|
4188
|
+
eventName,
|
|
4189
|
+
payloadLength: payload.length,
|
|
4190
|
+
matchedHandlers: matchingDefinitions.length,
|
|
4191
|
+
lastEventId
|
|
4192
|
+
});
|
|
4193
|
+
if (!matchingDefinitions.length) {
|
|
4194
|
+
return;
|
|
4195
|
+
}
|
|
4196
|
+
for (const eventDefinition of matchingDefinitions) {
|
|
4197
|
+
void this.handleSseEvent(eventDefinition, payload, safeUrl).catch((error) => {
|
|
4198
|
+
logRuntimeError("handleSseEvent", error, {
|
|
4199
|
+
eventName,
|
|
4200
|
+
url: safeUrl
|
|
4201
|
+
});
|
|
4202
|
+
});
|
|
4203
|
+
}
|
|
4204
|
+
};
|
|
4205
|
+
const processSseText = (chunk) => {
|
|
4206
|
+
let eventName = "message";
|
|
4207
|
+
let dataLines = [];
|
|
4208
|
+
const normalized = chunk.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
4209
|
+
const lines = normalized.split("\n");
|
|
4210
|
+
for (const line of lines) {
|
|
4211
|
+
if (!line) {
|
|
4212
|
+
flushSseChunk(eventName, dataLines);
|
|
4213
|
+
eventName = "message";
|
|
4214
|
+
dataLines = [];
|
|
4215
|
+
continue;
|
|
4216
|
+
}
|
|
4217
|
+
if (line.startsWith(":")) {
|
|
4218
|
+
continue;
|
|
4219
|
+
}
|
|
4220
|
+
const separatorIndex = line.indexOf(":");
|
|
4221
|
+
const field = separatorIndex >= 0 ? line.slice(0, separatorIndex) : line;
|
|
4222
|
+
let value = separatorIndex >= 0 ? line.slice(separatorIndex + 1) : "";
|
|
4223
|
+
if (value.startsWith(" ")) {
|
|
4224
|
+
value = value.slice(1);
|
|
4225
|
+
}
|
|
4226
|
+
switch (field) {
|
|
4227
|
+
case "event":
|
|
4228
|
+
eventName = value || "message";
|
|
4229
|
+
break;
|
|
4230
|
+
case "data":
|
|
4231
|
+
dataLines.push(value);
|
|
4232
|
+
break;
|
|
4233
|
+
case "id":
|
|
4234
|
+
if (!value.includes("\0")) {
|
|
4235
|
+
lastEventId = value;
|
|
4236
|
+
}
|
|
4237
|
+
break;
|
|
4238
|
+
case "retry": {
|
|
4239
|
+
const parsedDelay = Number.parseInt(value, 10);
|
|
4240
|
+
if (Number.isFinite(parsedDelay) && parsedDelay >= 0) {
|
|
4241
|
+
reconnectDelayMs = parsedDelay;
|
|
4242
|
+
}
|
|
4243
|
+
break;
|
|
4244
|
+
}
|
|
4245
|
+
default:
|
|
4246
|
+
break;
|
|
4247
|
+
}
|
|
4248
|
+
}
|
|
4249
|
+
flushSseChunk(eventName, dataLines);
|
|
4250
|
+
};
|
|
4251
|
+
const findEventBoundary = (value) => value.search(/\r?\n\r?\n/);
|
|
4252
|
+
const connectLoop = async () => {
|
|
4253
|
+
if (closed) {
|
|
4254
|
+
return;
|
|
4255
|
+
}
|
|
4256
|
+
connectionAttempt += 1;
|
|
4257
|
+
activeAbortController = new AbortController();
|
|
4258
|
+
let reconnectReason = "stream-ended";
|
|
4259
|
+
try {
|
|
4260
|
+
logRuntimeDebug(this.debugLogging, "sse-connect-attempt", {
|
|
4261
|
+
url: safeUrl,
|
|
4262
|
+
transport: "fetch",
|
|
4263
|
+
attempt: connectionAttempt,
|
|
4264
|
+
lastEventId
|
|
4265
|
+
});
|
|
4266
|
+
const headers = {
|
|
4267
|
+
Accept: "text/event-stream"
|
|
4268
|
+
};
|
|
4269
|
+
if (lastEventId) {
|
|
4270
|
+
headers["Last-Event-ID"] = lastEventId;
|
|
4271
|
+
}
|
|
4272
|
+
const response = await fetch(safeUrl, {
|
|
4273
|
+
method: "GET",
|
|
4274
|
+
headers,
|
|
4275
|
+
cache: "no-store",
|
|
4276
|
+
credentials: "same-origin",
|
|
4277
|
+
signal: activeAbortController.signal
|
|
4278
|
+
});
|
|
4279
|
+
if (!response.ok) {
|
|
4280
|
+
throw new Error(`SSE connection failed: ${response.status} ${response.statusText}`);
|
|
4281
|
+
}
|
|
4282
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
4283
|
+
if (!contentType.toLowerCase().includes("text/event-stream")) {
|
|
4284
|
+
throw new Error(`SSE response has unexpected content-type: ${contentType || "<empty>"}`);
|
|
4285
|
+
}
|
|
4286
|
+
logRuntimeDebug(this.debugLogging, "sse-open", {
|
|
4287
|
+
url: safeUrl,
|
|
4288
|
+
transport: "fetch",
|
|
4289
|
+
status: response.status,
|
|
4290
|
+
contentType,
|
|
4291
|
+
attempt: connectionAttempt,
|
|
4292
|
+
lastEventId,
|
|
4293
|
+
requestUsesLastEventIdHeader: Boolean(lastEventId)
|
|
4294
|
+
});
|
|
4295
|
+
if (!response.body || typeof response.body.getReader !== "function") {
|
|
4296
|
+
throw new Error("SSE streaming is not available in fetch response body");
|
|
4297
|
+
}
|
|
4298
|
+
const reader = response.body.getReader();
|
|
4299
|
+
const decoder = new TextDecoder();
|
|
4300
|
+
let buffer = "";
|
|
4301
|
+
let receivedChunkCount = 0;
|
|
4302
|
+
let receivedByteCount = 0;
|
|
4303
|
+
while (!closed) {
|
|
4304
|
+
const { done, value } = await reader.read();
|
|
4305
|
+
if (done) {
|
|
4306
|
+
break;
|
|
4307
|
+
}
|
|
4308
|
+
receivedChunkCount += 1;
|
|
4309
|
+
receivedByteCount += value?.byteLength ?? 0;
|
|
4310
|
+
buffer += decoder.decode(value, { stream: true });
|
|
4311
|
+
logRuntimeDebug(this.debugLogging, "sse-chunk", {
|
|
4312
|
+
url: safeUrl,
|
|
4313
|
+
transport: "fetch",
|
|
4314
|
+
chunkIndex: receivedChunkCount,
|
|
4315
|
+
chunkBytes: value?.byteLength ?? 0,
|
|
4316
|
+
totalBytes: receivedByteCount,
|
|
4317
|
+
bufferedChars: buffer.length
|
|
4318
|
+
});
|
|
4319
|
+
let boundaryIndex = findEventBoundary(buffer);
|
|
4320
|
+
while (boundaryIndex >= 0) {
|
|
4321
|
+
const rawChunk = buffer.slice(0, boundaryIndex);
|
|
4322
|
+
processSseText(rawChunk);
|
|
4323
|
+
buffer = buffer.slice(boundaryIndex).replace(/^\r?\n\r?\n/, "");
|
|
4324
|
+
boundaryIndex = findEventBoundary(buffer);
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
buffer += decoder.decode();
|
|
4328
|
+
if (buffer.trim()) {
|
|
4329
|
+
processSseText(buffer);
|
|
4330
|
+
}
|
|
4331
|
+
} catch (error) {
|
|
4332
|
+
if (closed || error instanceof DOMException && error.name === "AbortError") {
|
|
4333
|
+
return;
|
|
4334
|
+
}
|
|
4335
|
+
reconnectReason = error instanceof Error ? error.message : "stream-error";
|
|
4336
|
+
logRuntimeError("sseConnection", error, {
|
|
4337
|
+
url: safeUrl,
|
|
4338
|
+
transport: "fetch"
|
|
4339
|
+
});
|
|
4340
|
+
} finally {
|
|
4341
|
+
activeAbortController = null;
|
|
4342
|
+
}
|
|
4343
|
+
scheduleReconnect(reconnectReason);
|
|
4344
|
+
};
|
|
4345
|
+
const connection = {
|
|
4346
|
+
close: () => {
|
|
4347
|
+
closed = true;
|
|
4348
|
+
clearReconnectTimeout();
|
|
4349
|
+
activeAbortController?.abort();
|
|
4350
|
+
activeAbortController = null;
|
|
4351
|
+
}
|
|
4352
|
+
};
|
|
4353
|
+
void connectLoop().catch((error) => {
|
|
4354
|
+
logRuntimeError("sseConnection", error, {
|
|
4355
|
+
url: safeUrl,
|
|
4356
|
+
transport: "fetch"
|
|
4357
|
+
});
|
|
4358
|
+
});
|
|
4359
|
+
return connection;
|
|
4360
|
+
}
|
|
4361
|
+
async handleSseEvent(eventDefinition, rawData, url) {
|
|
4103
4362
|
let parsedMessage = {};
|
|
4104
4363
|
try {
|
|
4105
|
-
parsedMessage =
|
|
4364
|
+
parsedMessage = rawData ? JSON.parse(rawData) : {};
|
|
4106
4365
|
} catch {
|
|
4107
|
-
parsedMessage = { value:
|
|
4366
|
+
parsedMessage = { value: rawData ?? "" };
|
|
4108
4367
|
}
|
|
4109
4368
|
const message = eventDefinition.message ? sanitizeSchemaValue(eventDefinition.message, parsedMessage, `sse.${eventDefinition.name}`) : (() => {
|
|
4110
4369
|
throw new Error(`SSE event ${eventDefinition.name} must define message schema`);
|
|
4111
4370
|
})();
|
|
4112
4371
|
logRuntimeDebug(this.debugLogging, "sse", {
|
|
4113
4372
|
eventName: eventDefinition.name,
|
|
4114
|
-
raw:
|
|
4373
|
+
raw: rawData,
|
|
4115
4374
|
parsedMessage,
|
|
4116
|
-
message
|
|
4375
|
+
message,
|
|
4376
|
+
url
|
|
4117
4377
|
});
|
|
4118
4378
|
if (!eventDefinition.onEvent?.length) {
|
|
4119
4379
|
return;
|
|
@@ -4479,6 +4739,10 @@ var ReferenceRuntime = class {
|
|
|
4479
4739
|
return readPath(state, ["value"]);
|
|
4480
4740
|
case "isHidden":
|
|
4481
4741
|
return state.isHidden ?? true;
|
|
4742
|
+
case "isScrolledToTop":
|
|
4743
|
+
return state.isScrolledToTop ?? true;
|
|
4744
|
+
case "isScrolledToBottom":
|
|
4745
|
+
return state.isScrolledToBottom ?? true;
|
|
4482
4746
|
case "url":
|
|
4483
4747
|
return resolveInlineI18nValue(this.host, state.url ?? "");
|
|
4484
4748
|
case "base64":
|
|
@@ -7720,6 +7984,19 @@ function isGeneratedElementId(value) {
|
|
|
7720
7984
|
function isStepperEdit(node) {
|
|
7721
7985
|
return node.type === "number" || node.type === "float";
|
|
7722
7986
|
}
|
|
7987
|
+
function isScrollableWidgetNode(node) {
|
|
7988
|
+
switch (node.widget) {
|
|
7989
|
+
case "list":
|
|
7990
|
+
case "grid-view":
|
|
7991
|
+
case "listbox":
|
|
7992
|
+
case "combobox":
|
|
7993
|
+
return true;
|
|
7994
|
+
case "container-layout":
|
|
7995
|
+
return normalizeBoolean(node.verticallyScrollable, false);
|
|
7996
|
+
default:
|
|
7997
|
+
return false;
|
|
7998
|
+
}
|
|
7999
|
+
}
|
|
7723
8000
|
function getDateFormat(node) {
|
|
7724
8001
|
return node.format === "yyyy-MM-dd" ? "yyyy-MM-dd" : DEFAULT_DATE_FORMAT;
|
|
7725
8002
|
}
|
|
@@ -8056,6 +8333,7 @@ var RuntimeRenderer = class {
|
|
|
8056
8333
|
this.attachInputBehavior(this.root);
|
|
8057
8334
|
this.attachWidgetEvents(this.root);
|
|
8058
8335
|
restoreElementState(this.root, preservedState, this.stateByKey);
|
|
8336
|
+
this.syncAllScrollStateFlags();
|
|
8059
8337
|
this.applyPendingScrollAction();
|
|
8060
8338
|
this.applyPendingCursorAction();
|
|
8061
8339
|
this.activeContextMenu = adjustContextMenuPosition(this.root, this.activeContextMenu);
|
|
@@ -8674,7 +8952,9 @@ var RuntimeRenderer = class {
|
|
|
8674
8952
|
enabled: normalizeBoolean(node.enabled, true),
|
|
8675
8953
|
definitionSignature: buildDefinitionSignature(node.elements ?? []),
|
|
8676
8954
|
elements: deepClone(node.elements ?? []),
|
|
8677
|
-
selected: toFiniteNumber3(node.item) ?? toFiniteNumber3(node.selected) ?? -1
|
|
8955
|
+
selected: toFiniteNumber3(node.item) ?? toFiniteNumber3(node.selected) ?? -1,
|
|
8956
|
+
isScrolledToTop: true,
|
|
8957
|
+
isScrolledToBottom: true
|
|
8678
8958
|
};
|
|
8679
8959
|
break;
|
|
8680
8960
|
case "listbox":
|
|
@@ -8686,7 +8966,9 @@ var RuntimeRenderer = class {
|
|
|
8686
8966
|
enabled: normalizeBoolean(node.enabled, true),
|
|
8687
8967
|
definitionSignature: buildDefinitionSignature(node.elements ?? []),
|
|
8688
8968
|
listboxElements: deepClone(node.elements ?? []),
|
|
8689
|
-
selected: toFiniteNumber3(node.selected) ?? 0
|
|
8969
|
+
selected: toFiniteNumber3(node.selected) ?? 0,
|
|
8970
|
+
isScrolledToTop: true,
|
|
8971
|
+
isScrolledToBottom: true
|
|
8690
8972
|
};
|
|
8691
8973
|
break;
|
|
8692
8974
|
case "combobox":
|
|
@@ -8698,7 +8980,9 @@ var RuntimeRenderer = class {
|
|
|
8698
8980
|
enabled: normalizeBoolean(node.enabled, true),
|
|
8699
8981
|
definitionSignature: buildDefinitionSignature(node.elements ?? []),
|
|
8700
8982
|
comboboxElements: deepClone(node.elements ?? []),
|
|
8701
|
-
selected: toFiniteNumber3(node.selected) ?? 0
|
|
8983
|
+
selected: toFiniteNumber3(node.selected) ?? 0,
|
|
8984
|
+
isScrolledToTop: true,
|
|
8985
|
+
isScrolledToBottom: true
|
|
8702
8986
|
};
|
|
8703
8987
|
break;
|
|
8704
8988
|
case "radio-group":
|
|
@@ -8750,7 +9034,9 @@ var RuntimeRenderer = class {
|
|
|
8750
9034
|
widget: node.widget,
|
|
8751
9035
|
id: stateId,
|
|
8752
9036
|
name: node.name,
|
|
8753
|
-
enabled: normalizeBoolean(node.enabled, true)
|
|
9037
|
+
enabled: normalizeBoolean(node.enabled, true),
|
|
9038
|
+
isScrolledToTop: isScrollableWidgetNode(node) ? true : void 0,
|
|
9039
|
+
isScrolledToBottom: isScrollableWidgetNode(node) ? true : void 0
|
|
8754
9040
|
};
|
|
8755
9041
|
break;
|
|
8756
9042
|
}
|
|
@@ -9207,6 +9493,19 @@ var RuntimeRenderer = class {
|
|
|
9207
9493
|
redispatchUnderlyingClick: (x, y) => this.redispatchUnderlyingClick(x, y),
|
|
9208
9494
|
runActions: (actions, inputValue, context) => this.actionRuntime.runActions(actions, inputValue, context)
|
|
9209
9495
|
});
|
|
9496
|
+
for (const element of Array.from(root.querySelectorAll("[data-widget-key]"))) {
|
|
9497
|
+
const key = element.dataset.widgetKey;
|
|
9498
|
+
if (!key) {
|
|
9499
|
+
continue;
|
|
9500
|
+
}
|
|
9501
|
+
const node = this.nodeByKey.get(key);
|
|
9502
|
+
if (!node || !isScrollableWidgetNode(node)) {
|
|
9503
|
+
continue;
|
|
9504
|
+
}
|
|
9505
|
+
element.addEventListener("scroll", () => {
|
|
9506
|
+
this.syncScrollStateForElement(element, key);
|
|
9507
|
+
}, { passive: true });
|
|
9508
|
+
}
|
|
9210
9509
|
}
|
|
9211
9510
|
updateOwningListElementDescriptor(element, mutate) {
|
|
9212
9511
|
const listElement = element.closest(".vjt-list-element");
|
|
@@ -9525,6 +9824,7 @@ var RuntimeRenderer = class {
|
|
|
9525
9824
|
}
|
|
9526
9825
|
if (typeof window === "undefined") {
|
|
9527
9826
|
initialElement.scrollTop = Math.max(0, Math.min(targetTop, getMaxScrollTop(initialElement)));
|
|
9827
|
+
this.syncScrollStateForReference(reference, initialElement);
|
|
9528
9828
|
return;
|
|
9529
9829
|
}
|
|
9530
9830
|
if (this.activeScrollAnimationFrameId !== null) {
|
|
@@ -9536,6 +9836,7 @@ var RuntimeRenderer = class {
|
|
|
9536
9836
|
const delta = clampedTargetTop - startTop;
|
|
9537
9837
|
if (Math.abs(delta) < 1) {
|
|
9538
9838
|
initialElement.scrollTop = clampedTargetTop;
|
|
9839
|
+
this.syncScrollStateForReference(reference, initialElement);
|
|
9539
9840
|
return;
|
|
9540
9841
|
}
|
|
9541
9842
|
const durationMs = 300;
|
|
@@ -9551,10 +9852,12 @@ var RuntimeRenderer = class {
|
|
|
9551
9852
|
const progress = Math.min(1, elapsed / durationMs);
|
|
9552
9853
|
const liveTargetTop = Math.max(0, Math.min(clampedTargetTop, getMaxScrollTop(liveElement)));
|
|
9553
9854
|
liveElement.scrollTop = startTop + (liveTargetTop - startTop) * easeInOutCubic(progress);
|
|
9855
|
+
this.syncScrollStateForReference(reference, liveElement);
|
|
9554
9856
|
if (progress < 1) {
|
|
9555
9857
|
this.activeScrollAnimationFrameId = window.requestAnimationFrame(tick);
|
|
9556
9858
|
} else {
|
|
9557
9859
|
liveElement.scrollTop = liveTargetTop;
|
|
9860
|
+
this.syncScrollStateForReference(reference, liveElement);
|
|
9558
9861
|
this.activeScrollAnimationFrameId = null;
|
|
9559
9862
|
}
|
|
9560
9863
|
};
|
|
@@ -9608,6 +9911,48 @@ var RuntimeRenderer = class {
|
|
|
9608
9911
|
}
|
|
9609
9912
|
return null;
|
|
9610
9913
|
}
|
|
9914
|
+
syncAllScrollStateFlags() {
|
|
9915
|
+
if (!(this.root instanceof HTMLElement)) {
|
|
9916
|
+
return;
|
|
9917
|
+
}
|
|
9918
|
+
for (const element of Array.from(this.root.querySelectorAll("[data-widget-key]"))) {
|
|
9919
|
+
const key = element.dataset.widgetKey;
|
|
9920
|
+
if (!key) {
|
|
9921
|
+
continue;
|
|
9922
|
+
}
|
|
9923
|
+
const node = this.nodeByKey.get(key);
|
|
9924
|
+
if (!node || !isScrollableWidgetNode(node)) {
|
|
9925
|
+
continue;
|
|
9926
|
+
}
|
|
9927
|
+
this.syncScrollStateForElement(element, key);
|
|
9928
|
+
}
|
|
9929
|
+
}
|
|
9930
|
+
syncScrollStateForReference(reference, element) {
|
|
9931
|
+
const widgetId = reference.split(".")[0]?.trim();
|
|
9932
|
+
if (!widgetId) {
|
|
9933
|
+
return;
|
|
9934
|
+
}
|
|
9935
|
+
const targetElement = element ?? this.findScrollableWidgetElement(reference);
|
|
9936
|
+
if (!(targetElement instanceof HTMLElement)) {
|
|
9937
|
+
return;
|
|
9938
|
+
}
|
|
9939
|
+
const key = targetElement.dataset.widgetKey ?? widgetId;
|
|
9940
|
+
this.syncScrollStateForElement(targetElement, key);
|
|
9941
|
+
}
|
|
9942
|
+
syncScrollStateForElement(element, key) {
|
|
9943
|
+
const state = this.stateByKey.get(key) ?? this.stateById.get(key);
|
|
9944
|
+
if (!state) {
|
|
9945
|
+
return;
|
|
9946
|
+
}
|
|
9947
|
+
const maxScrollTop = Math.max(0, element.scrollHeight - element.clientHeight);
|
|
9948
|
+
if (maxScrollTop <= 1) {
|
|
9949
|
+
state.isScrolledToTop = true;
|
|
9950
|
+
state.isScrolledToBottom = true;
|
|
9951
|
+
return;
|
|
9952
|
+
}
|
|
9953
|
+
state.isScrolledToTop = element.scrollTop <= 1;
|
|
9954
|
+
state.isScrolledToBottom = element.scrollTop >= maxScrollTop - 1;
|
|
9955
|
+
}
|
|
9611
9956
|
toScrollableIndex(value) {
|
|
9612
9957
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
9613
9958
|
return Math.max(0, Math.trunc(value));
|
package/dist/lib/network.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActionDefinition, PrimitiveRequestType, RequestMapInput, RequestSchema, SseConfig } from './types.js';
|
|
1
|
+
import type { ActionDefinition, ClosableRuntimeResource, PrimitiveRequestType, RequestMapInput, RequestSchema, SseConfig } from './types.js';
|
|
2
2
|
type ActionRunner = (actions: ActionDefinition[], inputValue: unknown, context: {
|
|
3
3
|
currentValue: unknown;
|
|
4
4
|
responseValue?: unknown;
|
|
@@ -8,7 +8,7 @@ type NetworkRuntimeOptions = {
|
|
|
8
8
|
requestsMap: RequestMapInput;
|
|
9
9
|
sseConfigs: SseConfig[];
|
|
10
10
|
backendUrl?: string;
|
|
11
|
-
eventSources:
|
|
11
|
+
eventSources: ClosableRuntimeResource[];
|
|
12
12
|
runActions: ActionRunner;
|
|
13
13
|
rerenderRoot: () => Promise<void>;
|
|
14
14
|
};
|
|
@@ -28,6 +28,9 @@ export declare class NetworkRuntime {
|
|
|
28
28
|
private createRequestError;
|
|
29
29
|
private toRequestErrorPayload;
|
|
30
30
|
coercePrimitiveSchemaValue(type: PrimitiveRequestType, value: unknown): unknown;
|
|
31
|
+
private createSseConnection;
|
|
32
|
+
private createNativeSseConnection;
|
|
33
|
+
private createFetchSseConnection;
|
|
31
34
|
private handleSseEvent;
|
|
32
35
|
}
|
|
33
36
|
export {};
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ export type HeadingTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
|
6
6
|
export type WidgetEventName = 'onClick' | 'onUserValueChange' | 'onRefresh' | 'onEnter' | 'onShiftEnter' | 'onControlEnter' | 'onPaste';
|
|
7
7
|
export type SystemEventName = 'onBeforeRender' | 'onAfterRender' | 'onBeforeNavigate' | 'onAfterNavigate' | 'onLayoutSwitchToMobile' | 'onLayoutSwitchToDesktop' | 'onSpeechDetected' | 'onRecordingStarted' | 'onRecordingStopped' | 'onRecordingError' | 'onListeningError' | 'onListeringError' | 'onPlayFinished' | 'onPlayingStopped';
|
|
8
8
|
export type PrimitiveRequestType = 'int' | 'float' | 'boolean' | 'string';
|
|
9
|
+
export type ClosableRuntimeResource = {
|
|
10
|
+
close: () => void;
|
|
11
|
+
};
|
|
9
12
|
export type RouteDefinition = {
|
|
10
13
|
path: string;
|
|
11
14
|
ui: string;
|
|
@@ -128,6 +131,8 @@ export type WidgetState = {
|
|
|
128
131
|
modalHeight?: number;
|
|
129
132
|
activeTab?: number;
|
|
130
133
|
isHidden?: boolean;
|
|
134
|
+
isScrolledToTop?: boolean;
|
|
135
|
+
isScrolledToBottom?: boolean;
|
|
131
136
|
};
|
|
132
137
|
export type RuntimeSnapshot = {
|
|
133
138
|
stateByKey: Array<[string, WidgetState]>;
|