@gct-paas/word 0.1.38 → 0.1.41
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/core/data/DataManager.d.ts +15 -0
- package/dist/core/data/subtable-row.d.ts +17 -0
- package/dist/core/layout/LayoutContext.d.ts +2 -0
- package/dist/core/model/DocModel.d.ts +2 -2
- package/dist/index.es.js +2115 -140
- package/dist/runtime/_register_/runtime/SuiteRuntime.d.ts +4 -0
- package/dist/runtime/interface/change-diff.d.ts +2 -0
- package/dist/sdk/doc-runtime/check-table/map-check-table-item-infos.d.ts +1 -1
- package/dist/sdk/doc-runtime/composables/useDocOperations.d.ts +2 -0
- package/dist/sdk/doc-runtime/utils/wait-for-data-settle.d.ts +8 -0
- package/dist/sdk/engine/index.d.ts +0 -1
- package/dist/sdk/types/field-model-query.d.ts +2 -0
- package/dist/sdk/types/index.d.ts +20 -9
- package/dist/utils/func/render.d.ts +11 -3
- package/dist/word.css +12 -12
- package/package.json +5 -4
package/dist/index.es.js
CHANGED
|
@@ -16765,7 +16765,7 @@ function speedometer(samplesCount, min) {
|
|
|
16765
16765
|
let tail = 0;
|
|
16766
16766
|
let firstSampleTS;
|
|
16767
16767
|
min = min !== void 0 ? min : 1e3;
|
|
16768
|
-
return function
|
|
16768
|
+
return function push2(chunkLength) {
|
|
16769
16769
|
const now2 = Date.now();
|
|
16770
16770
|
const startedAt = timestamps[tail];
|
|
16771
16771
|
if (!firstSampleTS) {
|
|
@@ -18618,7 +18618,7 @@ function setupPlatformAdapters(options) {
|
|
|
18618
18618
|
triggerUtil.register({
|
|
18619
18619
|
handle: triggerHandler
|
|
18620
18620
|
});
|
|
18621
|
-
plugins?.forEach((
|
|
18621
|
+
plugins?.forEach((plugin2) => plugin2.install());
|
|
18622
18622
|
}
|
|
18623
18623
|
function setupVueRuntime(options) {
|
|
18624
18624
|
const { app } = options;
|
|
@@ -35239,7 +35239,7 @@ var ResizeObserver$1 = (
|
|
|
35239
35239
|
return (_a = observers.get(this))[method4].apply(_a, arguments);
|
|
35240
35240
|
};
|
|
35241
35241
|
});
|
|
35242
|
-
var index = (function() {
|
|
35242
|
+
var index$1 = (function() {
|
|
35243
35243
|
if (typeof global$1.ResizeObserver !== "undefined") {
|
|
35244
35244
|
return global$1.ResizeObserver;
|
|
35245
35245
|
}
|
|
@@ -35260,7 +35260,7 @@ function addResizeListener(element, fn) {
|
|
|
35260
35260
|
if (isServer) return;
|
|
35261
35261
|
if (!element.__resizeListeners__) {
|
|
35262
35262
|
element.__resizeListeners__ = [];
|
|
35263
|
-
element.__ro__ = new index(resizeHandler);
|
|
35263
|
+
element.__ro__ = new index$1(resizeHandler);
|
|
35264
35264
|
element.__ro__.observe(element);
|
|
35265
35265
|
}
|
|
35266
35266
|
element.__resizeListeners__.push(fn);
|
|
@@ -40919,6 +40919,22 @@ class LayoutContext {
|
|
|
40919
40919
|
this.paragraph?.addChild(run);
|
|
40920
40920
|
this.layoutRun = run;
|
|
40921
40921
|
}
|
|
40922
|
+
/** 子表可见行下标 → rawData 存储下标(跳过 deleted_ 行) */
|
|
40923
|
+
mapSubtableVisibleIndex(templatePath, visibleIndex, axis) {
|
|
40924
|
+
if (visibleIndex === void 0) return void 0;
|
|
40925
|
+
const parsed = parseValuePath(templatePath);
|
|
40926
|
+
const dm = this.doc.dataManager;
|
|
40927
|
+
if (axis === "n_y" && parsed.parentFieldPath) {
|
|
40928
|
+
return dm.resolveSubtableVisibleIndex(parsed.parentFieldPath, visibleIndex);
|
|
40929
|
+
}
|
|
40930
|
+
if (axis === "n_x" && parsed.linkFieldPath) {
|
|
40931
|
+
return dm.resolveSubtableVisibleIndex(parsed.linkFieldPath, visibleIndex);
|
|
40932
|
+
}
|
|
40933
|
+
if (parsed.isSubTable && parsed.parentFieldPath) {
|
|
40934
|
+
return dm.resolveSubtableVisibleIndex(parsed.parentFieldPath, visibleIndex);
|
|
40935
|
+
}
|
|
40936
|
+
return visibleIndex;
|
|
40937
|
+
}
|
|
40922
40938
|
/**
|
|
40923
40939
|
* 根据 dataIndex 替换 path 中的 [n] 为实际值
|
|
40924
40940
|
* @param path 包含 [n] 的路径,如 "$.items[n].name"
|
|
@@ -40928,7 +40944,11 @@ class LayoutContext {
|
|
|
40928
40944
|
if (!path2) return void 0;
|
|
40929
40945
|
const { type: type4, dataIndex, xDataIndex, yDataIndex, cellZone } = this.cell?.subRenderer || {};
|
|
40930
40946
|
if (isLinkSubTableType(type4) && cellZone === "cross") {
|
|
40931
|
-
return replacePathIndexPlaceholders({
|
|
40947
|
+
return replacePathIndexPlaceholders({
|
|
40948
|
+
x: this.mapSubtableVisibleIndex(path2, xDataIndex, "n_x"),
|
|
40949
|
+
y: this.mapSubtableVisibleIndex(path2, yDataIndex, "n_y"),
|
|
40950
|
+
templatePath: path2
|
|
40951
|
+
});
|
|
40932
40952
|
}
|
|
40933
40953
|
if (!path2.includes("[n]")) {
|
|
40934
40954
|
return path2;
|
|
@@ -40936,6 +40956,10 @@ class LayoutContext {
|
|
|
40936
40956
|
let n = dataIndex;
|
|
40937
40957
|
if (isLinkSubTableType(type4)) {
|
|
40938
40958
|
n = cellZone === "horizontal" ? yDataIndex : xDataIndex;
|
|
40959
|
+
const axis = cellZone === "horizontal" ? "n_y" : "n_x";
|
|
40960
|
+
n = this.mapSubtableVisibleIndex(path2, n, axis);
|
|
40961
|
+
} else {
|
|
40962
|
+
n = this.mapSubtableVisibleIndex(path2, n, "n");
|
|
40939
40963
|
}
|
|
40940
40964
|
if (n === void 0) return path2;
|
|
40941
40965
|
return replacePathIndexPlaceholder(n, path2);
|
|
@@ -42166,8 +42190,12 @@ function walkOoxmlElementTree(node, visit) {
|
|
|
42166
42190
|
function resolveItemCountByRegionId(runtimeJson, infos) {
|
|
42167
42191
|
const regions = listCheckTableRegionsInRuntimeJson(runtimeJson);
|
|
42168
42192
|
if (regions.length === 0) return {};
|
|
42169
|
-
const
|
|
42170
|
-
|
|
42193
|
+
const apiCount = infos.data?.length ?? 0;
|
|
42194
|
+
const itemCountByRegionId = {};
|
|
42195
|
+
for (const region of regions) {
|
|
42196
|
+
itemCountByRegionId[region.regionId] = Math.max(apiCount, 1);
|
|
42197
|
+
}
|
|
42198
|
+
return itemCountByRegionId;
|
|
42171
42199
|
}
|
|
42172
42200
|
function mergeCheckTableItemInfosIntoDefaults(defaultsMap, runtimeJson, infos, options) {
|
|
42173
42201
|
const regions = listCheckTableRegionsInRuntimeJson(runtimeJson);
|
|
@@ -42246,14 +42274,14 @@ const basicAttrs = {
|
|
|
42246
42274
|
required: [
|
|
42247
42275
|
{
|
|
42248
42276
|
from: "required_",
|
|
42249
|
-
to: "
|
|
42277
|
+
to: "required",
|
|
42250
42278
|
transform: (value) => Boolean(value)
|
|
42251
|
-
},
|
|
42252
|
-
{
|
|
42253
|
-
from: "_",
|
|
42254
|
-
to: "newSpecificConfig.newFieldName",
|
|
42255
|
-
transform: () => "值"
|
|
42256
42279
|
}
|
|
42280
|
+
// {
|
|
42281
|
+
// from: '_',
|
|
42282
|
+
// to: 'newSpecificConfig.newFieldName',
|
|
42283
|
+
// transform: () => '值',
|
|
42284
|
+
// },
|
|
42257
42285
|
],
|
|
42258
42286
|
placeholder: [{ from: "tip_text_", to: "placeholder" }],
|
|
42259
42287
|
showType: [
|
|
@@ -42366,7 +42394,7 @@ const DYN_CONFIG_BY_TYPE = {
|
|
|
42366
42394
|
},
|
|
42367
42395
|
{
|
|
42368
42396
|
from: "digits_",
|
|
42369
|
-
to: "newSpecificConfig.
|
|
42397
|
+
to: "newSpecificConfig.digits",
|
|
42370
42398
|
transform: (value) => {
|
|
42371
42399
|
const n = parseInt(String(value), 10);
|
|
42372
42400
|
return Number.isNaN(n) ? void 0 : n;
|
|
@@ -42384,11 +42412,57 @@ const DYN_CONFIG_BY_TYPE = {
|
|
|
42384
42412
|
...basicAttrs.showType,
|
|
42385
42413
|
{
|
|
42386
42414
|
from: "_",
|
|
42387
|
-
to: "
|
|
42388
|
-
transform: (_v, _t2, row) =>
|
|
42389
|
-
|
|
42390
|
-
|
|
42391
|
-
|
|
42415
|
+
to: "optionsJson",
|
|
42416
|
+
transform: (_v, _t2, row) => {
|
|
42417
|
+
const options = [
|
|
42418
|
+
{ label: row.true_text_ || "是", value: true, refFields: [], _item: {} },
|
|
42419
|
+
{ label: row.false_text_ || "否", value: false, refFields: [], _item: {} }
|
|
42420
|
+
];
|
|
42421
|
+
const json = JSON.stringify(options);
|
|
42422
|
+
return json;
|
|
42423
|
+
}
|
|
42424
|
+
},
|
|
42425
|
+
{
|
|
42426
|
+
from: "_",
|
|
42427
|
+
to: "computedOptions",
|
|
42428
|
+
transform: (_v, _t2, row) => {
|
|
42429
|
+
const options = [
|
|
42430
|
+
{ label: row.true_text_ || "是", value: true, refFields: [], _item: {} },
|
|
42431
|
+
{ label: row.false_text_ || "否", value: false, refFields: [], _item: {} }
|
|
42432
|
+
];
|
|
42433
|
+
const json = JSON.stringify(options);
|
|
42434
|
+
return json;
|
|
42435
|
+
}
|
|
42436
|
+
},
|
|
42437
|
+
{
|
|
42438
|
+
from: "_",
|
|
42439
|
+
to: "iconLabelSpace",
|
|
42440
|
+
transform: () => 8
|
|
42441
|
+
},
|
|
42442
|
+
{
|
|
42443
|
+
from: "_",
|
|
42444
|
+
to: "labelPosition",
|
|
42445
|
+
transform: () => "after"
|
|
42446
|
+
},
|
|
42447
|
+
{
|
|
42448
|
+
from: "_",
|
|
42449
|
+
to: "direction",
|
|
42450
|
+
transform: () => "landscape"
|
|
42451
|
+
},
|
|
42452
|
+
{
|
|
42453
|
+
from: "_",
|
|
42454
|
+
to: "controlSize",
|
|
42455
|
+
transform: () => 24
|
|
42456
|
+
},
|
|
42457
|
+
{
|
|
42458
|
+
from: "_",
|
|
42459
|
+
to: "controlEnumSpace",
|
|
42460
|
+
transform: () => 16
|
|
42461
|
+
},
|
|
42462
|
+
{
|
|
42463
|
+
from: "_",
|
|
42464
|
+
to: "showMode",
|
|
42465
|
+
transform: () => "both"
|
|
42392
42466
|
},
|
|
42393
42467
|
{ from: "validate_true_", to: "validateTrue" },
|
|
42394
42468
|
{ from: "validate_false_", to: "validateFalse" }
|
|
@@ -42494,12 +42568,6 @@ function buildPropsFromRow(row, config, baseProps = {}) {
|
|
|
42494
42568
|
const val = rowDef.transform ? rowDef.transform(raw, config.fieldType, row, baseProps) : raw;
|
|
42495
42569
|
if (val !== void 0) set(patch, rowDef.to, val);
|
|
42496
42570
|
}
|
|
42497
|
-
const options = get(patch, "newSpecificConfig.newOptions");
|
|
42498
|
-
if (Array.isArray(options) && options.length > 0) {
|
|
42499
|
-
const json = JSON.stringify(options);
|
|
42500
|
-
patch.computedOptions = json;
|
|
42501
|
-
patch.optionsJson = json;
|
|
42502
|
-
}
|
|
42503
42571
|
return patch;
|
|
42504
42572
|
}
|
|
42505
42573
|
function resolveFwType(fieldType, props) {
|
|
@@ -43770,7 +43838,8 @@ class TableExpander {
|
|
|
43770
43838
|
/** 编辑模式只展开一份;预览/填报模式按数据路径长度重复 */
|
|
43771
43839
|
getRepeatCount(region) {
|
|
43772
43840
|
if (this.doc.mode === DocModeTypeConst.Edit) return 1;
|
|
43773
|
-
|
|
43841
|
+
const path2 = region.subValuePath || region.valuePath;
|
|
43842
|
+
return this.data.countActiveSubtableRows(path2) || 1;
|
|
43774
43843
|
}
|
|
43775
43844
|
// ─── 循环子表 / 二维子表(纵向重复)────────────────────────
|
|
43776
43845
|
initializeRepeatingRowsInRange(region) {
|
|
@@ -44020,8 +44089,8 @@ class TableExpander {
|
|
|
44020
44089
|
if (this.doc.mode === DocModeTypeConst.Edit) return 1;
|
|
44021
44090
|
const path2 = region.subValuePath || region.valuePath;
|
|
44022
44091
|
if (path2) {
|
|
44023
|
-
const
|
|
44024
|
-
if (
|
|
44092
|
+
const activeCount = this.data.countActiveSubtableRows(path2);
|
|
44093
|
+
if (activeCount > 0) return activeCount;
|
|
44025
44094
|
}
|
|
44026
44095
|
return Math.max(1, region.end.row - region.start.row + 1);
|
|
44027
44096
|
}
|
|
@@ -46861,6 +46930,61 @@ class PostChangePipeline {
|
|
|
46861
46930
|
}
|
|
46862
46931
|
}
|
|
46863
46932
|
}
|
|
46933
|
+
function hasRowId(row) {
|
|
46934
|
+
const id = row.id_ ?? row.id;
|
|
46935
|
+
return id !== void 0 && id !== null && String(id).trim() !== "";
|
|
46936
|
+
}
|
|
46937
|
+
function hasPersistedCrossCell(rawData, tableKey, axis, row) {
|
|
46938
|
+
const uid = axis === "y" ? row.__gw_y_uid : row.__gw_x_uid;
|
|
46939
|
+
if (!uid) return false;
|
|
46940
|
+
const uidField = axis === "y" ? "__gw_y_uid" : "__gw_x_uid";
|
|
46941
|
+
for (const crossKey of Object.keys(rawData)) {
|
|
46942
|
+
if (!crossKey.includes(":")) continue;
|
|
46943
|
+
const [yKey, xKey] = crossKey.split(":");
|
|
46944
|
+
const onThisAxis = axis === "y" ? yKey === tableKey : xKey === tableKey;
|
|
46945
|
+
if (!onThisAxis) continue;
|
|
46946
|
+
const crossRows = rawData[crossKey];
|
|
46947
|
+
if (!Array.isArray(crossRows)) continue;
|
|
46948
|
+
if (crossRows.some((cell) => cell?.[uidField] === uid && hasRowId(cell))) {
|
|
46949
|
+
return true;
|
|
46950
|
+
}
|
|
46951
|
+
}
|
|
46952
|
+
return false;
|
|
46953
|
+
}
|
|
46954
|
+
function isPersistedSubtableRow(row, ctx) {
|
|
46955
|
+
if (!row || typeof row !== "object") return false;
|
|
46956
|
+
if (hasRowId(row)) return true;
|
|
46957
|
+
if (ctx?.rawData && ctx.tableKey && ctx.axis) {
|
|
46958
|
+
return hasPersistedCrossCell(ctx.rawData, ctx.tableKey, ctx.axis, row);
|
|
46959
|
+
}
|
|
46960
|
+
return false;
|
|
46961
|
+
}
|
|
46962
|
+
function countActiveSubtableRows(rows) {
|
|
46963
|
+
if (!Array.isArray(rows)) return 0;
|
|
46964
|
+
return rows.filter((row) => !row?.deleted_).length;
|
|
46965
|
+
}
|
|
46966
|
+
function resolveSubtableStorageIndex(rows, visibleIndex) {
|
|
46967
|
+
if (!Array.isArray(rows) || visibleIndex < 0) return visibleIndex;
|
|
46968
|
+
let seen = -1;
|
|
46969
|
+
for (let i = 0; i < rows.length; i++) {
|
|
46970
|
+
if (!rows[i]?.deleted_) {
|
|
46971
|
+
seen++;
|
|
46972
|
+
if (seen === visibleIndex) return i;
|
|
46973
|
+
}
|
|
46974
|
+
}
|
|
46975
|
+
return visibleIndex;
|
|
46976
|
+
}
|
|
46977
|
+
function resolveSubtableInsertIndex(rows, visibleIndex) {
|
|
46978
|
+
if (!Array.isArray(rows)) return 0;
|
|
46979
|
+
let seen = -1;
|
|
46980
|
+
for (let i = 0; i < rows.length; i++) {
|
|
46981
|
+
if (!rows[i]?.deleted_) {
|
|
46982
|
+
seen++;
|
|
46983
|
+
if (seen === visibleIndex) return i;
|
|
46984
|
+
}
|
|
46985
|
+
}
|
|
46986
|
+
return rows.length;
|
|
46987
|
+
}
|
|
46864
46988
|
const DEFAULT_EMPTY_ITEM = Object.freeze({ __gw_default: true });
|
|
46865
46989
|
class DataManager {
|
|
46866
46990
|
doc;
|
|
@@ -46947,6 +47071,17 @@ class DataManager {
|
|
|
46947
47071
|
getLabel(path2) {
|
|
46948
47072
|
return this.get(this.getLabelPath(path2)) || this.get(path2);
|
|
46949
47073
|
}
|
|
47074
|
+
/** 子表数组路径下未软删行数 */
|
|
47075
|
+
countActiveSubtableRows(arrayPath) {
|
|
47076
|
+
const rows = this.getByPath(this.rawData, arrayPath);
|
|
47077
|
+
return countActiveSubtableRows(rows);
|
|
47078
|
+
}
|
|
47079
|
+
/** 版面可见行下标 → rawData 数组实际下标 */
|
|
47080
|
+
resolveSubtableVisibleIndex(arrayPath, visibleIndex) {
|
|
47081
|
+
const rows = this.getByPath(this.rawData, arrayPath);
|
|
47082
|
+
if (!Array.isArray(rows)) return visibleIndex;
|
|
47083
|
+
return resolveSubtableStorageIndex(rows, visibleIndex);
|
|
47084
|
+
}
|
|
46950
47085
|
assignField(target, fieldPath, value) {
|
|
46951
47086
|
if (!fieldPath.includes(".") && !fieldPath.includes("[")) {
|
|
46952
47087
|
target[fieldPath] = value;
|
|
@@ -47348,7 +47483,8 @@ class DataManager {
|
|
|
47348
47483
|
arr = [{ ...DEFAULT_EMPTY_ITEM }];
|
|
47349
47484
|
this.set(path2, arr);
|
|
47350
47485
|
}
|
|
47351
|
-
|
|
47486
|
+
const storageIndex = resolveSubtableInsertIndex(arr, index2);
|
|
47487
|
+
if (storageIndex < 0 || storageIndex > arr.length) {
|
|
47352
47488
|
throw new Error(`Index ${index2} out of bounds for array of length ${arr.length}`);
|
|
47353
47489
|
}
|
|
47354
47490
|
const oldValue = [...arr];
|
|
@@ -47357,9 +47493,9 @@ class DataManager {
|
|
|
47357
47493
|
const clonedValues = values.map(
|
|
47358
47494
|
(value) => axisInfo ? this.prepareAxisRowForInsert(arr, axisInfo, value) : this.deepClone(value)
|
|
47359
47495
|
);
|
|
47360
|
-
arr.splice(
|
|
47496
|
+
arr.splice(storageIndex, 0, ...clonedValues);
|
|
47361
47497
|
if (axisInfo) {
|
|
47362
|
-
for (let i =
|
|
47498
|
+
for (let i = storageIndex; i < arr.length; i++) {
|
|
47363
47499
|
this.ensureAxisRowAndUid(tableKey, i, axisInfo.axis);
|
|
47364
47500
|
}
|
|
47365
47501
|
}
|
|
@@ -47382,14 +47518,26 @@ class DataManager {
|
|
|
47382
47518
|
if (!Array.isArray(arr)) {
|
|
47383
47519
|
throw new Error(`Path "${path2}" is not an array`);
|
|
47384
47520
|
}
|
|
47385
|
-
|
|
47521
|
+
const storageIndex = resolveSubtableStorageIndex(arr, index2);
|
|
47522
|
+
if (storageIndex < 0 || storageIndex >= arr.length) {
|
|
47386
47523
|
throw new Error(`Index ${index2} out of bounds for array of length ${arr.length}`);
|
|
47387
47524
|
}
|
|
47388
|
-
const oldValue = [...arr];
|
|
47389
|
-
const removedValue = arr.splice(index2, 1)[0];
|
|
47390
|
-
this.emit(path2, arr, oldValue);
|
|
47391
47525
|
const tableKey = path2.replace(/^\$\./, "").replace(/\[(n|\d+)\]/g, "");
|
|
47392
47526
|
const axisInfo = this.resolveAxisByTableKey(tableKey);
|
|
47527
|
+
const row = arr[storageIndex];
|
|
47528
|
+
if (isPersistedSubtableRow(row, {
|
|
47529
|
+
rawData: this.rawData,
|
|
47530
|
+
tableKey,
|
|
47531
|
+
axis: axisInfo?.axis
|
|
47532
|
+
})) {
|
|
47533
|
+
const oldValue2 = this.deepClone(arr);
|
|
47534
|
+
row.deleted_ = true;
|
|
47535
|
+
this.emit(path2, arr, oldValue2);
|
|
47536
|
+
return row;
|
|
47537
|
+
}
|
|
47538
|
+
const oldValue = [...arr];
|
|
47539
|
+
const removedValue = arr.splice(storageIndex, 1)[0];
|
|
47540
|
+
this.emit(path2, arr, oldValue);
|
|
47393
47541
|
if (axisInfo) {
|
|
47394
47542
|
const uidField = axisInfo.axis === "y" ? "__gw_y_uid" : "__gw_x_uid";
|
|
47395
47543
|
this.cleanupCrossByAxisUid(tableKey, axisInfo.axis, removedValue?.[uidField]);
|
|
@@ -47470,6 +47618,52 @@ class DataManager {
|
|
|
47470
47618
|
}
|
|
47471
47619
|
}
|
|
47472
47620
|
}
|
|
47621
|
+
this.syncSubTableRowsToLayout();
|
|
47622
|
+
}
|
|
47623
|
+
/**
|
|
47624
|
+
* 补齐二维/检验表的关联轴子表(如 f_ewblink / f_jianyan2)到动态关联铺砖槽位数。
|
|
47625
|
+
* 不处理主体轴(如 f_ewb / f_jianyan1),避免覆盖接口行或误扩纵向轴。
|
|
47626
|
+
*/
|
|
47627
|
+
syncSubTableRowsToLayout() {
|
|
47628
|
+
const listSubTables = this.doc?.model?.getSubTableInfoList;
|
|
47629
|
+
if (typeof listSubTables !== "function") return;
|
|
47630
|
+
for (const info of listSubTables.call(this.doc?.model)) {
|
|
47631
|
+
if (!info.field || !["check-table-2d-link", "sub-table-2d-link"].includes(info.subType)) {
|
|
47632
|
+
continue;
|
|
47633
|
+
}
|
|
47634
|
+
const linkFieldKey = info.field;
|
|
47635
|
+
const layoutRows = this.doc?.model?.getSubTableLayoutSlotCount(linkFieldKey) ?? 0;
|
|
47636
|
+
if (layoutRows <= 0) continue;
|
|
47637
|
+
const dataRows = this.countSubTableDataRows(linkFieldKey);
|
|
47638
|
+
const targetRows = Math.max(dataRows, layoutRows);
|
|
47639
|
+
if (targetRows <= dataRows) continue;
|
|
47640
|
+
this.ensureCheckTableLinkLayoutRows(linkFieldKey, targetRows);
|
|
47641
|
+
}
|
|
47642
|
+
}
|
|
47643
|
+
/** 子表在 rawData 中的行数(支持尚未转成数组的 { data: [] } 接口形态,此时返回 0 且不在此阶段强转) */
|
|
47644
|
+
countSubTableDataRows(subTableKey) {
|
|
47645
|
+
const existing = this.rawData?.[subTableKey];
|
|
47646
|
+
if (Array.isArray(existing)) return existing.length;
|
|
47647
|
+
if (existing?.data && Array.isArray(existing.data)) return existing.data.length;
|
|
47648
|
+
return 0;
|
|
47649
|
+
}
|
|
47650
|
+
/**
|
|
47651
|
+
* 为检验表关联轴补足铺砖行:占位标记 + __gw_x_uid(与 push/insert 行为一致)。
|
|
47652
|
+
*/
|
|
47653
|
+
ensureCheckTableLinkLayoutRows(linkFieldKey, rowCount) {
|
|
47654
|
+
const raw = this.rawData?.[linkFieldKey];
|
|
47655
|
+
if (raw != null && !Array.isArray(raw)) {
|
|
47656
|
+
return;
|
|
47657
|
+
}
|
|
47658
|
+
let arr = raw;
|
|
47659
|
+
if (!Array.isArray(arr)) {
|
|
47660
|
+
arr = [];
|
|
47661
|
+
this.rawData[linkFieldKey] = arr;
|
|
47662
|
+
}
|
|
47663
|
+
for (let i = arr.length; i < rowCount; i++) {
|
|
47664
|
+
arr.push({ ...DEFAULT_EMPTY_ITEM });
|
|
47665
|
+
this.ensureAxisRowAndUid(linkFieldKey, i, "x");
|
|
47666
|
+
}
|
|
47473
47667
|
}
|
|
47474
47668
|
applyInitDataCrossWildcard(path2, value) {
|
|
47475
47669
|
const parse = parseValuePath(path2);
|
|
@@ -47512,8 +47706,7 @@ class DataManager {
|
|
|
47512
47706
|
* layoutRows 为 0(如二维表纵向 f_ewb)时不按分组扩行,仅保证至少 1 行可绑定。
|
|
47513
47707
|
*/
|
|
47514
47708
|
resolveInitRowCount(subTableKey) {
|
|
47515
|
-
const
|
|
47516
|
-
const dataRows = Array.isArray(existing) ? existing.length : 0;
|
|
47709
|
+
const dataRows = this.countSubTableDataRows(subTableKey);
|
|
47517
47710
|
const layoutRows = this.doc?.model?.getSubTableLayoutSlotCount(subTableKey) ?? 1;
|
|
47518
47711
|
if (layoutRows > 0) {
|
|
47519
47712
|
return Math.max(dataRows, layoutRows);
|
|
@@ -47525,7 +47718,11 @@ class DataManager {
|
|
|
47525
47718
|
* @param asPlaceholder true:push/insert 用的系统占位行(带 __gw_default);false:applyInitData 物化行(空对象)
|
|
47526
47719
|
*/
|
|
47527
47720
|
ensureSubTableRowCount(subTableKey, rowCount, asPlaceholder = true) {
|
|
47528
|
-
|
|
47721
|
+
const raw = this.rawData?.[subTableKey];
|
|
47722
|
+
if (raw != null && !Array.isArray(raw)) {
|
|
47723
|
+
return [];
|
|
47724
|
+
}
|
|
47725
|
+
let arr = raw;
|
|
47529
47726
|
if (!Array.isArray(arr)) {
|
|
47530
47727
|
arr = [];
|
|
47531
47728
|
this.rawData[subTableKey] = arr;
|
|
@@ -50108,13 +50305,15 @@ class DocModel {
|
|
|
50108
50305
|
};
|
|
50109
50306
|
});
|
|
50110
50307
|
const table2DRegions = tables.filter((w2) => w2.has2DTable).flatMap((w2) => w2._2DTable).map((item) => {
|
|
50308
|
+
const crossKey = item.subFieldKey && item.linkFieldKey ? `${item.subFieldKey}:${item.linkFieldKey}` : void 0;
|
|
50111
50309
|
const result = [];
|
|
50112
50310
|
if (item.subFieldKey) {
|
|
50113
50311
|
result.push({
|
|
50114
50312
|
field: item.subFieldKey,
|
|
50115
50313
|
key: "dyn",
|
|
50116
50314
|
name: "二维表",
|
|
50117
|
-
subType: "sub-table-2d"
|
|
50315
|
+
subType: "sub-table-2d",
|
|
50316
|
+
crossKey
|
|
50118
50317
|
});
|
|
50119
50318
|
}
|
|
50120
50319
|
if (item.linkFieldKey) {
|
|
@@ -50122,19 +50321,22 @@ class DocModel {
|
|
|
50122
50321
|
field: item.linkFieldKey,
|
|
50123
50322
|
key: "newfixed",
|
|
50124
50323
|
name: "二维表-关联",
|
|
50125
|
-
subType: "sub-table-2d-link"
|
|
50324
|
+
subType: "sub-table-2d-link",
|
|
50325
|
+
crossKey
|
|
50126
50326
|
});
|
|
50127
50327
|
}
|
|
50128
50328
|
return result;
|
|
50129
50329
|
}).flat();
|
|
50130
50330
|
const checkTableRegions = tables.filter((w2) => w2.hasCheckTable).flatMap((w2) => w2.checkTable).map((item) => {
|
|
50331
|
+
const crossKey = item.subFieldKey && item.linkFieldKey ? `${item.subFieldKey}:${item.linkFieldKey}` : void 0;
|
|
50131
50332
|
const result = [];
|
|
50132
50333
|
if (item.subFieldKey) {
|
|
50133
50334
|
result.push({
|
|
50134
50335
|
field: item.subFieldKey,
|
|
50135
50336
|
key: "newfixed",
|
|
50136
50337
|
name: "检验表-动态",
|
|
50137
|
-
subType: "check-table-2d"
|
|
50338
|
+
subType: "check-table-2d",
|
|
50339
|
+
crossKey
|
|
50138
50340
|
});
|
|
50139
50341
|
}
|
|
50140
50342
|
if (item.linkFieldKey) {
|
|
@@ -50142,7 +50344,8 @@ class DocModel {
|
|
|
50142
50344
|
field: item.linkFieldKey,
|
|
50143
50345
|
key: "newfixed",
|
|
50144
50346
|
name: "检验表-关联",
|
|
50145
|
-
subType: "check-table-2d-link"
|
|
50347
|
+
subType: "check-table-2d-link",
|
|
50348
|
+
crossKey
|
|
50146
50349
|
});
|
|
50147
50350
|
}
|
|
50148
50351
|
return result;
|
|
@@ -50153,8 +50356,8 @@ class DocModel {
|
|
|
50153
50356
|
* 根据版面数据分组 / 动态关联铺砖,计算子表字段在 rawData 中应初始化的行数。
|
|
50154
50357
|
*
|
|
50155
50358
|
* - 固定表:槽位归 subFieldKey(bounded + itemRegion)
|
|
50156
|
-
* - 二维表 /
|
|
50157
|
-
* 纵向 subFieldKey(如
|
|
50359
|
+
* - 二维表 / 检验表:动态分组铺砖槽位归 linkFieldKey(如 f_jianyan2);
|
|
50360
|
+
* 纵向 subFieldKey(如 f_jianyan1)由检验项条数撑行,返回 0
|
|
50158
50361
|
* - 其它子表无分组:返回 1
|
|
50159
50362
|
*/
|
|
50160
50363
|
getSubTableLayoutSlotCount(subFieldKey) {
|
|
@@ -50166,15 +50369,14 @@ class DocModel {
|
|
|
50166
50369
|
if (region.subFieldKey !== subFieldKey || !region.itemRegion) continue;
|
|
50167
50370
|
const fillDirection = region.widgetMeta?.props?.fillDirection ?? "x";
|
|
50168
50371
|
max = Math.max(max, countDataGroupSlots(region, region.itemRegion, fillDirection));
|
|
50169
|
-
region.type;
|
|
50170
50372
|
}
|
|
50171
50373
|
for (const region of [...table.checkTable, ...table._2DTable]) {
|
|
50172
50374
|
if (!region.itemRegion) continue;
|
|
50173
50375
|
const range3 = expandDataGroupRowRange(region, region.itemRegion);
|
|
50174
|
-
const
|
|
50376
|
+
const fillDirection = region.widgetMeta?.props?.fillDirection ?? "x";
|
|
50377
|
+
const slots = countDataGroupSlots(range3, region.itemRegion, fillDirection);
|
|
50175
50378
|
if (region.linkFieldKey === subFieldKey) {
|
|
50176
50379
|
max = Math.max(max, slots);
|
|
50177
|
-
region.type;
|
|
50178
50380
|
}
|
|
50179
50381
|
if (region.subFieldKey === subFieldKey) {
|
|
50180
50382
|
isLinkSubTableSubAxisOnly = true;
|
|
@@ -51581,63 +51783,48 @@ function transformSourceDataList(data, dict = {}) {
|
|
|
51581
51783
|
return list || [];
|
|
51582
51784
|
}
|
|
51583
51785
|
function conversionFormState(payload) {
|
|
51584
|
-
const { interfaceData, masterSlaveList,
|
|
51786
|
+
const { interfaceData, masterSlaveList, subTableInfoList } = payload || {};
|
|
51585
51787
|
const formState = {};
|
|
51586
51788
|
if (interfaceData && interfaceData.data) {
|
|
51587
51789
|
merge(formState, transformSourceData(interfaceData.data, interfaceData.dict));
|
|
51588
51790
|
}
|
|
51589
|
-
|
|
51590
|
-
|
|
51591
|
-
const
|
|
51592
|
-
|
|
51593
|
-
|
|
51594
|
-
|
|
51595
|
-
|
|
51596
|
-
|
|
51597
|
-
|
|
51598
|
-
};
|
|
51599
|
-
|
|
51600
|
-
|
|
51601
|
-
|
|
51602
|
-
|
|
51603
|
-
|
|
51604
|
-
|
|
51605
|
-
|
|
51606
|
-
|
|
51607
|
-
|
|
51608
|
-
|
|
51609
|
-
|
|
51610
|
-
|
|
51611
|
-
|
|
51612
|
-
|
|
51613
|
-
|
|
51614
|
-
|
|
51615
|
-
|
|
51616
|
-
|
|
51617
|
-
|
|
51618
|
-
|
|
51619
|
-
|
|
51620
|
-
|
|
51621
|
-
|
|
51622
|
-
dict: parentState?.dict || []
|
|
51623
|
-
};
|
|
51624
|
-
const addedYUids = [];
|
|
51625
|
-
formState[parentFieldKey] = {
|
|
51626
|
-
data: [],
|
|
51627
|
-
dict: formState[parentFieldKey]?.dict || []
|
|
51628
|
-
};
|
|
51629
|
-
parentState?.data.forEach((row) => {
|
|
51630
|
-
const yUid = row.group_.split(":")[0];
|
|
51631
|
-
if (addedYUids.includes(yUid)) return;
|
|
51632
|
-
addedYUids.push(yUid);
|
|
51633
|
-
formState[parentFieldKey].data.push({
|
|
51634
|
-
...row,
|
|
51635
|
-
__gw_y_uid: yUid
|
|
51636
|
-
});
|
|
51791
|
+
const crossKeyList = Array.from(new Set(subTableInfoList.map((o) => o.crossKey).filter(Boolean)));
|
|
51792
|
+
crossKeyList.forEach((crossKey) => {
|
|
51793
|
+
const [parentFieldKey, linkFieldKey] = crossKey.split(":");
|
|
51794
|
+
const parentState = formState[parentFieldKey];
|
|
51795
|
+
formState[linkFieldKey]?.data.forEach((row) => {
|
|
51796
|
+
row.__gw_x_uid = row.group_;
|
|
51797
|
+
});
|
|
51798
|
+
formState[crossKey] = {
|
|
51799
|
+
data: parentState?.data.map((row) => {
|
|
51800
|
+
const { group_ } = row;
|
|
51801
|
+
const _row = { ...row };
|
|
51802
|
+
if (group_) {
|
|
51803
|
+
const [yid, xid] = group_.split(":");
|
|
51804
|
+
_row.__gw_y_uid = yid;
|
|
51805
|
+
_row.__gw_x_uid = xid;
|
|
51806
|
+
}
|
|
51807
|
+
return _row;
|
|
51808
|
+
}) || [],
|
|
51809
|
+
dict: parentState?.dict || []
|
|
51810
|
+
};
|
|
51811
|
+
const addedYids = [];
|
|
51812
|
+
formState[parentFieldKey] = {
|
|
51813
|
+
data: [],
|
|
51814
|
+
dict: formState[parentFieldKey]?.dict || []
|
|
51815
|
+
};
|
|
51816
|
+
parentState?.data.forEach((row) => {
|
|
51817
|
+
if (!row.group_?.includes(":")) return;
|
|
51818
|
+
const yid = row.group_.split(":")[0];
|
|
51819
|
+
if (addedYids.includes(yid)) return;
|
|
51820
|
+
addedYids.push(yid);
|
|
51821
|
+
formState[parentFieldKey].data.push({
|
|
51822
|
+
...row,
|
|
51823
|
+
__gw_y_uid: yid
|
|
51637
51824
|
});
|
|
51638
51825
|
});
|
|
51639
|
-
}
|
|
51640
|
-
masterSlaveList.map((item) => item.key).concat(
|
|
51826
|
+
});
|
|
51827
|
+
masterSlaveList.map((item) => item.key).concat(crossKeyList).forEach((k) => {
|
|
51641
51828
|
const subFormData = formState[k];
|
|
51642
51829
|
if (subFormData) {
|
|
51643
51830
|
formState[k] = transformSourceDataList([...subFormData.data], subFormData.dict);
|
|
@@ -51645,27 +51832,38 @@ function conversionFormState(payload) {
|
|
|
51645
51832
|
});
|
|
51646
51833
|
return formState;
|
|
51647
51834
|
}
|
|
51648
|
-
function
|
|
51835
|
+
function resolveSubmitCrossKeys(formData, subTableInfoList) {
|
|
51836
|
+
if (subTableInfoList?.length) {
|
|
51837
|
+
const fromModel = [
|
|
51838
|
+
...new Set(
|
|
51839
|
+
subTableInfoList.map((item) => item.crossKey).filter((key) => typeof key === "string" && key.length > 0)
|
|
51840
|
+
)
|
|
51841
|
+
];
|
|
51842
|
+
if (fromModel.length) return fromModel;
|
|
51843
|
+
}
|
|
51844
|
+
return Object.keys(formData).filter((k) => k.includes(":"));
|
|
51845
|
+
}
|
|
51846
|
+
function getSubmitFormData(formData, subTableInfoList) {
|
|
51649
51847
|
const _formData = { ...formData };
|
|
51650
|
-
|
|
51651
|
-
const [subKey] =
|
|
51652
|
-
const
|
|
51653
|
-
const
|
|
51654
|
-
|
|
51655
|
-
|
|
51656
|
-
|
|
51657
|
-
|
|
51658
|
-
|
|
51659
|
-
|
|
51848
|
+
resolveSubmitCrossKeys(_formData, subTableInfoList).forEach((crossKey) => {
|
|
51849
|
+
const [subKey, linkKey] = crossKey.split(":");
|
|
51850
|
+
const subData = _formData[subKey] || [];
|
|
51851
|
+
const linkData = _formData[linkKey] || [];
|
|
51852
|
+
const crossData = _formData[crossKey] || [];
|
|
51853
|
+
_formData[subKey] = [];
|
|
51854
|
+
subData.forEach((subRow) => {
|
|
51855
|
+
const { __gw_y_uid: yid } = subRow;
|
|
51856
|
+
linkData.forEach((linkRow) => {
|
|
51857
|
+
const { __gw_x_uid: xid } = linkRow;
|
|
51858
|
+
const crossRow = crossData.find((row) => row.__gw_y_uid === yid && row.__gw_x_uid === xid) || {};
|
|
51660
51859
|
_formData[subKey].push({
|
|
51661
|
-
|
|
51662
|
-
|
|
51663
|
-
|
|
51664
|
-
...omit(obj, FILTER_KEYS)
|
|
51860
|
+
...subRow,
|
|
51861
|
+
...omit(crossRow, FILTER_KEYS),
|
|
51862
|
+
group_: `${yid}:${xid}`
|
|
51665
51863
|
});
|
|
51666
51864
|
});
|
|
51667
|
-
}
|
|
51668
|
-
delete _formData[
|
|
51865
|
+
});
|
|
51866
|
+
delete _formData[crossKey];
|
|
51669
51867
|
});
|
|
51670
51868
|
const realFormData = Object.keys(_formData).reduce((reducedData, fieldKey) => {
|
|
51671
51869
|
const fieldValue = _formData[fieldKey];
|
|
@@ -52445,6 +52643,1750 @@ async function loadDataValuesByAutofillRules(record, ctx, instances, autofillRul
|
|
|
52445
52643
|
{ needReplacePathIndexPlaceholder: true, sourceValuePath }
|
|
52446
52644
|
);
|
|
52447
52645
|
}
|
|
52646
|
+
class Hooks {
|
|
52647
|
+
/**
|
|
52648
|
+
* @callback HookCallback
|
|
52649
|
+
* @this {*|Jsep} this
|
|
52650
|
+
* @param {Jsep} env
|
|
52651
|
+
* @returns: void
|
|
52652
|
+
*/
|
|
52653
|
+
/**
|
|
52654
|
+
* Adds the given callback to the list of callbacks for the given hook.
|
|
52655
|
+
*
|
|
52656
|
+
* The callback will be invoked when the hook it is registered for is run.
|
|
52657
|
+
*
|
|
52658
|
+
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
52659
|
+
*
|
|
52660
|
+
* @param {string|object} name The name of the hook, or an object of callbacks keyed by name
|
|
52661
|
+
* @param {HookCallback|boolean} callback The callback function which is given environment variables.
|
|
52662
|
+
* @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)
|
|
52663
|
+
* @public
|
|
52664
|
+
*/
|
|
52665
|
+
add(name2, callback, first) {
|
|
52666
|
+
if (typeof arguments[0] != "string") {
|
|
52667
|
+
for (let name3 in arguments[0]) {
|
|
52668
|
+
this.add(name3, arguments[0][name3], arguments[1]);
|
|
52669
|
+
}
|
|
52670
|
+
} else {
|
|
52671
|
+
(Array.isArray(name2) ? name2 : [name2]).forEach(function(name3) {
|
|
52672
|
+
this[name3] = this[name3] || [];
|
|
52673
|
+
if (callback) {
|
|
52674
|
+
this[name3][first ? "unshift" : "push"](callback);
|
|
52675
|
+
}
|
|
52676
|
+
}, this);
|
|
52677
|
+
}
|
|
52678
|
+
}
|
|
52679
|
+
/**
|
|
52680
|
+
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
52681
|
+
*
|
|
52682
|
+
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
52683
|
+
*
|
|
52684
|
+
* @param {string} name The name of the hook.
|
|
52685
|
+
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
52686
|
+
* @public
|
|
52687
|
+
*/
|
|
52688
|
+
run(name2, env) {
|
|
52689
|
+
this[name2] = this[name2] || [];
|
|
52690
|
+
this[name2].forEach(function(callback) {
|
|
52691
|
+
callback.call(env && env.context ? env.context : env, env);
|
|
52692
|
+
});
|
|
52693
|
+
}
|
|
52694
|
+
}
|
|
52695
|
+
class Plugins {
|
|
52696
|
+
constructor(jsep2) {
|
|
52697
|
+
this.jsep = jsep2;
|
|
52698
|
+
this.registered = {};
|
|
52699
|
+
}
|
|
52700
|
+
/**
|
|
52701
|
+
* @callback PluginSetup
|
|
52702
|
+
* @this {Jsep} jsep
|
|
52703
|
+
* @returns: void
|
|
52704
|
+
*/
|
|
52705
|
+
/**
|
|
52706
|
+
* Adds the given plugin(s) to the registry
|
|
52707
|
+
*
|
|
52708
|
+
* @param {object} plugins
|
|
52709
|
+
* @param {string} plugins.name The name of the plugin
|
|
52710
|
+
* @param {PluginSetup} plugins.init The init function
|
|
52711
|
+
* @public
|
|
52712
|
+
*/
|
|
52713
|
+
register() {
|
|
52714
|
+
for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
52715
|
+
plugins[_key] = arguments[_key];
|
|
52716
|
+
}
|
|
52717
|
+
plugins.forEach((plugin2) => {
|
|
52718
|
+
if (typeof plugin2 !== "object" || !plugin2.name || !plugin2.init) {
|
|
52719
|
+
throw new Error("Invalid JSEP plugin format");
|
|
52720
|
+
}
|
|
52721
|
+
if (this.registered[plugin2.name]) {
|
|
52722
|
+
return;
|
|
52723
|
+
}
|
|
52724
|
+
plugin2.init(this.jsep);
|
|
52725
|
+
this.registered[plugin2.name] = plugin2;
|
|
52726
|
+
});
|
|
52727
|
+
}
|
|
52728
|
+
}
|
|
52729
|
+
class Jsep {
|
|
52730
|
+
/**
|
|
52731
|
+
* @returns {string}
|
|
52732
|
+
*/
|
|
52733
|
+
static get version() {
|
|
52734
|
+
return "1.4.0";
|
|
52735
|
+
}
|
|
52736
|
+
/**
|
|
52737
|
+
* @returns {string}
|
|
52738
|
+
*/
|
|
52739
|
+
static toString() {
|
|
52740
|
+
return "JavaScript Expression Parser (JSEP) v" + Jsep.version;
|
|
52741
|
+
}
|
|
52742
|
+
// ==================== CONFIG ================================
|
|
52743
|
+
/**
|
|
52744
|
+
* @method addUnaryOp
|
|
52745
|
+
* @param {string} op_name The name of the unary op to add
|
|
52746
|
+
* @returns {Jsep}
|
|
52747
|
+
*/
|
|
52748
|
+
static addUnaryOp(op_name) {
|
|
52749
|
+
Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
|
|
52750
|
+
Jsep.unary_ops[op_name] = 1;
|
|
52751
|
+
return Jsep;
|
|
52752
|
+
}
|
|
52753
|
+
/**
|
|
52754
|
+
* @method jsep.addBinaryOp
|
|
52755
|
+
* @param {string} op_name The name of the binary op to add
|
|
52756
|
+
* @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence
|
|
52757
|
+
* @param {boolean} [isRightAssociative=false] whether operator is right-associative
|
|
52758
|
+
* @returns {Jsep}
|
|
52759
|
+
*/
|
|
52760
|
+
static addBinaryOp(op_name, precedence, isRightAssociative) {
|
|
52761
|
+
Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
|
|
52762
|
+
Jsep.binary_ops[op_name] = precedence;
|
|
52763
|
+
if (isRightAssociative) {
|
|
52764
|
+
Jsep.right_associative.add(op_name);
|
|
52765
|
+
} else {
|
|
52766
|
+
Jsep.right_associative.delete(op_name);
|
|
52767
|
+
}
|
|
52768
|
+
return Jsep;
|
|
52769
|
+
}
|
|
52770
|
+
/**
|
|
52771
|
+
* @method addIdentifierChar
|
|
52772
|
+
* @param {string} char The additional character to treat as a valid part of an identifier
|
|
52773
|
+
* @returns {Jsep}
|
|
52774
|
+
*/
|
|
52775
|
+
static addIdentifierChar(char) {
|
|
52776
|
+
Jsep.additional_identifier_chars.add(char);
|
|
52777
|
+
return Jsep;
|
|
52778
|
+
}
|
|
52779
|
+
/**
|
|
52780
|
+
* @method addLiteral
|
|
52781
|
+
* @param {string} literal_name The name of the literal to add
|
|
52782
|
+
* @param {*} literal_value The value of the literal
|
|
52783
|
+
* @returns {Jsep}
|
|
52784
|
+
*/
|
|
52785
|
+
static addLiteral(literal_name, literal_value) {
|
|
52786
|
+
Jsep.literals[literal_name] = literal_value;
|
|
52787
|
+
return Jsep;
|
|
52788
|
+
}
|
|
52789
|
+
/**
|
|
52790
|
+
* @method removeUnaryOp
|
|
52791
|
+
* @param {string} op_name The name of the unary op to remove
|
|
52792
|
+
* @returns {Jsep}
|
|
52793
|
+
*/
|
|
52794
|
+
static removeUnaryOp(op_name) {
|
|
52795
|
+
delete Jsep.unary_ops[op_name];
|
|
52796
|
+
if (op_name.length === Jsep.max_unop_len) {
|
|
52797
|
+
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
52798
|
+
}
|
|
52799
|
+
return Jsep;
|
|
52800
|
+
}
|
|
52801
|
+
/**
|
|
52802
|
+
* @method removeAllUnaryOps
|
|
52803
|
+
* @returns {Jsep}
|
|
52804
|
+
*/
|
|
52805
|
+
static removeAllUnaryOps() {
|
|
52806
|
+
Jsep.unary_ops = {};
|
|
52807
|
+
Jsep.max_unop_len = 0;
|
|
52808
|
+
return Jsep;
|
|
52809
|
+
}
|
|
52810
|
+
/**
|
|
52811
|
+
* @method removeIdentifierChar
|
|
52812
|
+
* @param {string} char The additional character to stop treating as a valid part of an identifier
|
|
52813
|
+
* @returns {Jsep}
|
|
52814
|
+
*/
|
|
52815
|
+
static removeIdentifierChar(char) {
|
|
52816
|
+
Jsep.additional_identifier_chars.delete(char);
|
|
52817
|
+
return Jsep;
|
|
52818
|
+
}
|
|
52819
|
+
/**
|
|
52820
|
+
* @method removeBinaryOp
|
|
52821
|
+
* @param {string} op_name The name of the binary op to remove
|
|
52822
|
+
* @returns {Jsep}
|
|
52823
|
+
*/
|
|
52824
|
+
static removeBinaryOp(op_name) {
|
|
52825
|
+
delete Jsep.binary_ops[op_name];
|
|
52826
|
+
if (op_name.length === Jsep.max_binop_len) {
|
|
52827
|
+
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
52828
|
+
}
|
|
52829
|
+
Jsep.right_associative.delete(op_name);
|
|
52830
|
+
return Jsep;
|
|
52831
|
+
}
|
|
52832
|
+
/**
|
|
52833
|
+
* @method removeAllBinaryOps
|
|
52834
|
+
* @returns {Jsep}
|
|
52835
|
+
*/
|
|
52836
|
+
static removeAllBinaryOps() {
|
|
52837
|
+
Jsep.binary_ops = {};
|
|
52838
|
+
Jsep.max_binop_len = 0;
|
|
52839
|
+
return Jsep;
|
|
52840
|
+
}
|
|
52841
|
+
/**
|
|
52842
|
+
* @method removeLiteral
|
|
52843
|
+
* @param {string} literal_name The name of the literal to remove
|
|
52844
|
+
* @returns {Jsep}
|
|
52845
|
+
*/
|
|
52846
|
+
static removeLiteral(literal_name) {
|
|
52847
|
+
delete Jsep.literals[literal_name];
|
|
52848
|
+
return Jsep;
|
|
52849
|
+
}
|
|
52850
|
+
/**
|
|
52851
|
+
* @method removeAllLiterals
|
|
52852
|
+
* @returns {Jsep}
|
|
52853
|
+
*/
|
|
52854
|
+
static removeAllLiterals() {
|
|
52855
|
+
Jsep.literals = {};
|
|
52856
|
+
return Jsep;
|
|
52857
|
+
}
|
|
52858
|
+
// ==================== END CONFIG ============================
|
|
52859
|
+
/**
|
|
52860
|
+
* @returns {string}
|
|
52861
|
+
*/
|
|
52862
|
+
get char() {
|
|
52863
|
+
return this.expr.charAt(this.index);
|
|
52864
|
+
}
|
|
52865
|
+
/**
|
|
52866
|
+
* @returns {number}
|
|
52867
|
+
*/
|
|
52868
|
+
get code() {
|
|
52869
|
+
return this.expr.charCodeAt(this.index);
|
|
52870
|
+
}
|
|
52871
|
+
/**
|
|
52872
|
+
* @param {string} expr a string with the passed in express
|
|
52873
|
+
* @returns Jsep
|
|
52874
|
+
*/
|
|
52875
|
+
constructor(expr) {
|
|
52876
|
+
this.expr = expr;
|
|
52877
|
+
this.index = 0;
|
|
52878
|
+
}
|
|
52879
|
+
/**
|
|
52880
|
+
* static top-level parser
|
|
52881
|
+
* @returns {jsep.Expression}
|
|
52882
|
+
*/
|
|
52883
|
+
static parse(expr) {
|
|
52884
|
+
return new Jsep(expr).parse();
|
|
52885
|
+
}
|
|
52886
|
+
/**
|
|
52887
|
+
* Get the longest key length of any object
|
|
52888
|
+
* @param {object} obj
|
|
52889
|
+
* @returns {number}
|
|
52890
|
+
*/
|
|
52891
|
+
static getMaxKeyLen(obj) {
|
|
52892
|
+
return Math.max(0, ...Object.keys(obj).map((k) => k.length));
|
|
52893
|
+
}
|
|
52894
|
+
/**
|
|
52895
|
+
* `ch` is a character code in the next three functions
|
|
52896
|
+
* @param {number} ch
|
|
52897
|
+
* @returns {boolean}
|
|
52898
|
+
*/
|
|
52899
|
+
static isDecimalDigit(ch) {
|
|
52900
|
+
return ch >= 48 && ch <= 57;
|
|
52901
|
+
}
|
|
52902
|
+
/**
|
|
52903
|
+
* Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.
|
|
52904
|
+
* @param {string} op_val
|
|
52905
|
+
* @returns {number}
|
|
52906
|
+
*/
|
|
52907
|
+
static binaryPrecedence(op_val) {
|
|
52908
|
+
return Jsep.binary_ops[op_val] || 0;
|
|
52909
|
+
}
|
|
52910
|
+
/**
|
|
52911
|
+
* Looks for start of identifier
|
|
52912
|
+
* @param {number} ch
|
|
52913
|
+
* @returns {boolean}
|
|
52914
|
+
*/
|
|
52915
|
+
static isIdentifierStart(ch) {
|
|
52916
|
+
return ch >= 65 && ch <= 90 || // A...Z
|
|
52917
|
+
ch >= 97 && ch <= 122 || // a...z
|
|
52918
|
+
ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)] || // any non-ASCII that is not an operator
|
|
52919
|
+
Jsep.additional_identifier_chars.has(String.fromCharCode(ch));
|
|
52920
|
+
}
|
|
52921
|
+
/**
|
|
52922
|
+
* @param {number} ch
|
|
52923
|
+
* @returns {boolean}
|
|
52924
|
+
*/
|
|
52925
|
+
static isIdentifierPart(ch) {
|
|
52926
|
+
return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
|
|
52927
|
+
}
|
|
52928
|
+
/**
|
|
52929
|
+
* throw error at index of the expression
|
|
52930
|
+
* @param {string} message
|
|
52931
|
+
* @throws
|
|
52932
|
+
*/
|
|
52933
|
+
throwError(message) {
|
|
52934
|
+
const error = new Error(message + " at character " + this.index);
|
|
52935
|
+
error.index = this.index;
|
|
52936
|
+
error.description = message;
|
|
52937
|
+
throw error;
|
|
52938
|
+
}
|
|
52939
|
+
/**
|
|
52940
|
+
* Run a given hook
|
|
52941
|
+
* @param {string} name
|
|
52942
|
+
* @param {jsep.Expression|false} [node]
|
|
52943
|
+
* @returns {?jsep.Expression}
|
|
52944
|
+
*/
|
|
52945
|
+
runHook(name2, node) {
|
|
52946
|
+
if (Jsep.hooks[name2]) {
|
|
52947
|
+
const env = {
|
|
52948
|
+
context: this,
|
|
52949
|
+
node
|
|
52950
|
+
};
|
|
52951
|
+
Jsep.hooks.run(name2, env);
|
|
52952
|
+
return env.node;
|
|
52953
|
+
}
|
|
52954
|
+
return node;
|
|
52955
|
+
}
|
|
52956
|
+
/**
|
|
52957
|
+
* Runs a given hook until one returns a node
|
|
52958
|
+
* @param {string} name
|
|
52959
|
+
* @returns {?jsep.Expression}
|
|
52960
|
+
*/
|
|
52961
|
+
searchHook(name2) {
|
|
52962
|
+
if (Jsep.hooks[name2]) {
|
|
52963
|
+
const env = {
|
|
52964
|
+
context: this
|
|
52965
|
+
};
|
|
52966
|
+
Jsep.hooks[name2].find(function(callback) {
|
|
52967
|
+
callback.call(env.context, env);
|
|
52968
|
+
return env.node;
|
|
52969
|
+
});
|
|
52970
|
+
return env.node;
|
|
52971
|
+
}
|
|
52972
|
+
}
|
|
52973
|
+
/**
|
|
52974
|
+
* Push `index` up to the next non-space character
|
|
52975
|
+
*/
|
|
52976
|
+
gobbleSpaces() {
|
|
52977
|
+
let ch = this.code;
|
|
52978
|
+
while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) {
|
|
52979
|
+
ch = this.expr.charCodeAt(++this.index);
|
|
52980
|
+
}
|
|
52981
|
+
this.runHook("gobble-spaces");
|
|
52982
|
+
}
|
|
52983
|
+
/**
|
|
52984
|
+
* Top-level method to parse all expressions and returns compound or single node
|
|
52985
|
+
* @returns {jsep.Expression}
|
|
52986
|
+
*/
|
|
52987
|
+
parse() {
|
|
52988
|
+
this.runHook("before-all");
|
|
52989
|
+
const nodes = this.gobbleExpressions();
|
|
52990
|
+
const node = nodes.length === 1 ? nodes[0] : {
|
|
52991
|
+
type: Jsep.COMPOUND,
|
|
52992
|
+
body: nodes
|
|
52993
|
+
};
|
|
52994
|
+
return this.runHook("after-all", node);
|
|
52995
|
+
}
|
|
52996
|
+
/**
|
|
52997
|
+
* top-level parser (but can be reused within as well)
|
|
52998
|
+
* @param {number} [untilICode]
|
|
52999
|
+
* @returns {jsep.Expression[]}
|
|
53000
|
+
*/
|
|
53001
|
+
gobbleExpressions(untilICode) {
|
|
53002
|
+
let nodes = [], ch_i, node;
|
|
53003
|
+
while (this.index < this.expr.length) {
|
|
53004
|
+
ch_i = this.code;
|
|
53005
|
+
if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
|
|
53006
|
+
this.index++;
|
|
53007
|
+
} else {
|
|
53008
|
+
if (node = this.gobbleExpression()) {
|
|
53009
|
+
nodes.push(node);
|
|
53010
|
+
} else if (this.index < this.expr.length) {
|
|
53011
|
+
if (ch_i === untilICode) {
|
|
53012
|
+
break;
|
|
53013
|
+
}
|
|
53014
|
+
this.throwError('Unexpected "' + this.char + '"');
|
|
53015
|
+
}
|
|
53016
|
+
}
|
|
53017
|
+
}
|
|
53018
|
+
return nodes;
|
|
53019
|
+
}
|
|
53020
|
+
/**
|
|
53021
|
+
* The main parsing function.
|
|
53022
|
+
* @returns {?jsep.Expression}
|
|
53023
|
+
*/
|
|
53024
|
+
gobbleExpression() {
|
|
53025
|
+
const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
|
|
53026
|
+
this.gobbleSpaces();
|
|
53027
|
+
return this.runHook("after-expression", node);
|
|
53028
|
+
}
|
|
53029
|
+
/**
|
|
53030
|
+
* Search for the operation portion of the string (e.g. `+`, `===`)
|
|
53031
|
+
* Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)
|
|
53032
|
+
* and move down from 3 to 2 to 1 character until a matching binary operation is found
|
|
53033
|
+
* then, return that binary operation
|
|
53034
|
+
* @returns {string|boolean}
|
|
53035
|
+
*/
|
|
53036
|
+
gobbleBinaryOp() {
|
|
53037
|
+
this.gobbleSpaces();
|
|
53038
|
+
let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
|
|
53039
|
+
let tc_len = to_check.length;
|
|
53040
|
+
while (tc_len > 0) {
|
|
53041
|
+
if (Jsep.binary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
|
|
53042
|
+
this.index += tc_len;
|
|
53043
|
+
return to_check;
|
|
53044
|
+
}
|
|
53045
|
+
to_check = to_check.substr(0, --tc_len);
|
|
53046
|
+
}
|
|
53047
|
+
return false;
|
|
53048
|
+
}
|
|
53049
|
+
/**
|
|
53050
|
+
* This function is responsible for gobbling an individual expression,
|
|
53051
|
+
* e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`
|
|
53052
|
+
* @returns {?jsep.BinaryExpression}
|
|
53053
|
+
*/
|
|
53054
|
+
gobbleBinaryExpression() {
|
|
53055
|
+
let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
|
|
53056
|
+
left = this.gobbleToken();
|
|
53057
|
+
if (!left) {
|
|
53058
|
+
return left;
|
|
53059
|
+
}
|
|
53060
|
+
biop = this.gobbleBinaryOp();
|
|
53061
|
+
if (!biop) {
|
|
53062
|
+
return left;
|
|
53063
|
+
}
|
|
53064
|
+
biop_info = {
|
|
53065
|
+
value: biop,
|
|
53066
|
+
prec: Jsep.binaryPrecedence(biop),
|
|
53067
|
+
right_a: Jsep.right_associative.has(biop)
|
|
53068
|
+
};
|
|
53069
|
+
right = this.gobbleToken();
|
|
53070
|
+
if (!right) {
|
|
53071
|
+
this.throwError("Expected expression after " + biop);
|
|
53072
|
+
}
|
|
53073
|
+
stack = [left, biop_info, right];
|
|
53074
|
+
while (biop = this.gobbleBinaryOp()) {
|
|
53075
|
+
prec = Jsep.binaryPrecedence(biop);
|
|
53076
|
+
if (prec === 0) {
|
|
53077
|
+
this.index -= biop.length;
|
|
53078
|
+
break;
|
|
53079
|
+
}
|
|
53080
|
+
biop_info = {
|
|
53081
|
+
value: biop,
|
|
53082
|
+
prec,
|
|
53083
|
+
right_a: Jsep.right_associative.has(biop)
|
|
53084
|
+
};
|
|
53085
|
+
cur_biop = biop;
|
|
53086
|
+
const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
|
|
53087
|
+
while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
|
|
53088
|
+
right = stack.pop();
|
|
53089
|
+
biop = stack.pop().value;
|
|
53090
|
+
left = stack.pop();
|
|
53091
|
+
node = {
|
|
53092
|
+
type: Jsep.BINARY_EXP,
|
|
53093
|
+
operator: biop,
|
|
53094
|
+
left,
|
|
53095
|
+
right
|
|
53096
|
+
};
|
|
53097
|
+
stack.push(node);
|
|
53098
|
+
}
|
|
53099
|
+
node = this.gobbleToken();
|
|
53100
|
+
if (!node) {
|
|
53101
|
+
this.throwError("Expected expression after " + cur_biop);
|
|
53102
|
+
}
|
|
53103
|
+
stack.push(biop_info, node);
|
|
53104
|
+
}
|
|
53105
|
+
i = stack.length - 1;
|
|
53106
|
+
node = stack[i];
|
|
53107
|
+
while (i > 1) {
|
|
53108
|
+
node = {
|
|
53109
|
+
type: Jsep.BINARY_EXP,
|
|
53110
|
+
operator: stack[i - 1].value,
|
|
53111
|
+
left: stack[i - 2],
|
|
53112
|
+
right: node
|
|
53113
|
+
};
|
|
53114
|
+
i -= 2;
|
|
53115
|
+
}
|
|
53116
|
+
return node;
|
|
53117
|
+
}
|
|
53118
|
+
/**
|
|
53119
|
+
* An individual part of a binary expression:
|
|
53120
|
+
* e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis)
|
|
53121
|
+
* @returns {boolean|jsep.Expression}
|
|
53122
|
+
*/
|
|
53123
|
+
gobbleToken() {
|
|
53124
|
+
let ch, to_check, tc_len, node;
|
|
53125
|
+
this.gobbleSpaces();
|
|
53126
|
+
node = this.searchHook("gobble-token");
|
|
53127
|
+
if (node) {
|
|
53128
|
+
return this.runHook("after-token", node);
|
|
53129
|
+
}
|
|
53130
|
+
ch = this.code;
|
|
53131
|
+
if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
|
|
53132
|
+
return this.gobbleNumericLiteral();
|
|
53133
|
+
}
|
|
53134
|
+
if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
|
|
53135
|
+
node = this.gobbleStringLiteral();
|
|
53136
|
+
} else if (ch === Jsep.OBRACK_CODE) {
|
|
53137
|
+
node = this.gobbleArray();
|
|
53138
|
+
} else {
|
|
53139
|
+
to_check = this.expr.substr(this.index, Jsep.max_unop_len);
|
|
53140
|
+
tc_len = to_check.length;
|
|
53141
|
+
while (tc_len > 0) {
|
|
53142
|
+
if (Jsep.unary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
|
|
53143
|
+
this.index += tc_len;
|
|
53144
|
+
const argument = this.gobbleToken();
|
|
53145
|
+
if (!argument) {
|
|
53146
|
+
this.throwError("missing unaryOp argument");
|
|
53147
|
+
}
|
|
53148
|
+
return this.runHook("after-token", {
|
|
53149
|
+
type: Jsep.UNARY_EXP,
|
|
53150
|
+
operator: to_check,
|
|
53151
|
+
argument,
|
|
53152
|
+
prefix: true
|
|
53153
|
+
});
|
|
53154
|
+
}
|
|
53155
|
+
to_check = to_check.substr(0, --tc_len);
|
|
53156
|
+
}
|
|
53157
|
+
if (Jsep.isIdentifierStart(ch)) {
|
|
53158
|
+
node = this.gobbleIdentifier();
|
|
53159
|
+
if (Jsep.literals.hasOwnProperty(node.name)) {
|
|
53160
|
+
node = {
|
|
53161
|
+
type: Jsep.LITERAL,
|
|
53162
|
+
value: Jsep.literals[node.name],
|
|
53163
|
+
raw: node.name
|
|
53164
|
+
};
|
|
53165
|
+
} else if (node.name === Jsep.this_str) {
|
|
53166
|
+
node = {
|
|
53167
|
+
type: Jsep.THIS_EXP
|
|
53168
|
+
};
|
|
53169
|
+
}
|
|
53170
|
+
} else if (ch === Jsep.OPAREN_CODE) {
|
|
53171
|
+
node = this.gobbleGroup();
|
|
53172
|
+
}
|
|
53173
|
+
}
|
|
53174
|
+
if (!node) {
|
|
53175
|
+
return this.runHook("after-token", false);
|
|
53176
|
+
}
|
|
53177
|
+
node = this.gobbleTokenProperty(node);
|
|
53178
|
+
return this.runHook("after-token", node);
|
|
53179
|
+
}
|
|
53180
|
+
/**
|
|
53181
|
+
* Gobble properties of of identifiers/strings/arrays/groups.
|
|
53182
|
+
* e.g. `foo`, `bar.baz`, `foo['bar'].baz`
|
|
53183
|
+
* It also gobbles function calls:
|
|
53184
|
+
* e.g. `Math.acos(obj.angle)`
|
|
53185
|
+
* @param {jsep.Expression} node
|
|
53186
|
+
* @returns {jsep.Expression}
|
|
53187
|
+
*/
|
|
53188
|
+
gobbleTokenProperty(node) {
|
|
53189
|
+
this.gobbleSpaces();
|
|
53190
|
+
let ch = this.code;
|
|
53191
|
+
while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {
|
|
53192
|
+
let optional;
|
|
53193
|
+
if (ch === Jsep.QUMARK_CODE) {
|
|
53194
|
+
if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {
|
|
53195
|
+
break;
|
|
53196
|
+
}
|
|
53197
|
+
optional = true;
|
|
53198
|
+
this.index += 2;
|
|
53199
|
+
this.gobbleSpaces();
|
|
53200
|
+
ch = this.code;
|
|
53201
|
+
}
|
|
53202
|
+
this.index++;
|
|
53203
|
+
if (ch === Jsep.OBRACK_CODE) {
|
|
53204
|
+
node = {
|
|
53205
|
+
type: Jsep.MEMBER_EXP,
|
|
53206
|
+
computed: true,
|
|
53207
|
+
object: node,
|
|
53208
|
+
property: this.gobbleExpression()
|
|
53209
|
+
};
|
|
53210
|
+
if (!node.property) {
|
|
53211
|
+
this.throwError('Unexpected "' + this.char + '"');
|
|
53212
|
+
}
|
|
53213
|
+
this.gobbleSpaces();
|
|
53214
|
+
ch = this.code;
|
|
53215
|
+
if (ch !== Jsep.CBRACK_CODE) {
|
|
53216
|
+
this.throwError("Unclosed [");
|
|
53217
|
+
}
|
|
53218
|
+
this.index++;
|
|
53219
|
+
} else if (ch === Jsep.OPAREN_CODE) {
|
|
53220
|
+
node = {
|
|
53221
|
+
type: Jsep.CALL_EXP,
|
|
53222
|
+
"arguments": this.gobbleArguments(Jsep.CPAREN_CODE),
|
|
53223
|
+
callee: node
|
|
53224
|
+
};
|
|
53225
|
+
} else if (ch === Jsep.PERIOD_CODE || optional) {
|
|
53226
|
+
if (optional) {
|
|
53227
|
+
this.index--;
|
|
53228
|
+
}
|
|
53229
|
+
this.gobbleSpaces();
|
|
53230
|
+
node = {
|
|
53231
|
+
type: Jsep.MEMBER_EXP,
|
|
53232
|
+
computed: false,
|
|
53233
|
+
object: node,
|
|
53234
|
+
property: this.gobbleIdentifier()
|
|
53235
|
+
};
|
|
53236
|
+
}
|
|
53237
|
+
if (optional) {
|
|
53238
|
+
node.optional = true;
|
|
53239
|
+
}
|
|
53240
|
+
this.gobbleSpaces();
|
|
53241
|
+
ch = this.code;
|
|
53242
|
+
}
|
|
53243
|
+
return node;
|
|
53244
|
+
}
|
|
53245
|
+
/**
|
|
53246
|
+
* Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to
|
|
53247
|
+
* keep track of everything in the numeric literal and then calling `parseFloat` on that string
|
|
53248
|
+
* @returns {jsep.Literal}
|
|
53249
|
+
*/
|
|
53250
|
+
gobbleNumericLiteral() {
|
|
53251
|
+
let number4 = "", ch, chCode;
|
|
53252
|
+
while (Jsep.isDecimalDigit(this.code)) {
|
|
53253
|
+
number4 += this.expr.charAt(this.index++);
|
|
53254
|
+
}
|
|
53255
|
+
if (this.code === Jsep.PERIOD_CODE) {
|
|
53256
|
+
number4 += this.expr.charAt(this.index++);
|
|
53257
|
+
while (Jsep.isDecimalDigit(this.code)) {
|
|
53258
|
+
number4 += this.expr.charAt(this.index++);
|
|
53259
|
+
}
|
|
53260
|
+
}
|
|
53261
|
+
ch = this.char;
|
|
53262
|
+
if (ch === "e" || ch === "E") {
|
|
53263
|
+
number4 += this.expr.charAt(this.index++);
|
|
53264
|
+
ch = this.char;
|
|
53265
|
+
if (ch === "+" || ch === "-") {
|
|
53266
|
+
number4 += this.expr.charAt(this.index++);
|
|
53267
|
+
}
|
|
53268
|
+
while (Jsep.isDecimalDigit(this.code)) {
|
|
53269
|
+
number4 += this.expr.charAt(this.index++);
|
|
53270
|
+
}
|
|
53271
|
+
if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
|
|
53272
|
+
this.throwError("Expected exponent (" + number4 + this.char + ")");
|
|
53273
|
+
}
|
|
53274
|
+
}
|
|
53275
|
+
chCode = this.code;
|
|
53276
|
+
if (Jsep.isIdentifierStart(chCode)) {
|
|
53277
|
+
this.throwError("Variable names cannot start with a number (" + number4 + this.char + ")");
|
|
53278
|
+
} else if (chCode === Jsep.PERIOD_CODE || number4.length === 1 && number4.charCodeAt(0) === Jsep.PERIOD_CODE) {
|
|
53279
|
+
this.throwError("Unexpected period");
|
|
53280
|
+
}
|
|
53281
|
+
return {
|
|
53282
|
+
type: Jsep.LITERAL,
|
|
53283
|
+
value: parseFloat(number4),
|
|
53284
|
+
raw: number4
|
|
53285
|
+
};
|
|
53286
|
+
}
|
|
53287
|
+
/**
|
|
53288
|
+
* Parses a string literal, staring with single or double quotes with basic support for escape codes
|
|
53289
|
+
* e.g. `"hello world"`, `'this is\nJSEP'`
|
|
53290
|
+
* @returns {jsep.Literal}
|
|
53291
|
+
*/
|
|
53292
|
+
gobbleStringLiteral() {
|
|
53293
|
+
let str = "";
|
|
53294
|
+
const startIndex = this.index;
|
|
53295
|
+
const quote = this.expr.charAt(this.index++);
|
|
53296
|
+
let closed = false;
|
|
53297
|
+
while (this.index < this.expr.length) {
|
|
53298
|
+
let ch = this.expr.charAt(this.index++);
|
|
53299
|
+
if (ch === quote) {
|
|
53300
|
+
closed = true;
|
|
53301
|
+
break;
|
|
53302
|
+
} else if (ch === "\\") {
|
|
53303
|
+
ch = this.expr.charAt(this.index++);
|
|
53304
|
+
switch (ch) {
|
|
53305
|
+
case "n":
|
|
53306
|
+
str += "\n";
|
|
53307
|
+
break;
|
|
53308
|
+
case "r":
|
|
53309
|
+
str += "\r";
|
|
53310
|
+
break;
|
|
53311
|
+
case "t":
|
|
53312
|
+
str += " ";
|
|
53313
|
+
break;
|
|
53314
|
+
case "b":
|
|
53315
|
+
str += "\b";
|
|
53316
|
+
break;
|
|
53317
|
+
case "f":
|
|
53318
|
+
str += "\f";
|
|
53319
|
+
break;
|
|
53320
|
+
case "v":
|
|
53321
|
+
str += "\v";
|
|
53322
|
+
break;
|
|
53323
|
+
default:
|
|
53324
|
+
str += ch;
|
|
53325
|
+
}
|
|
53326
|
+
} else {
|
|
53327
|
+
str += ch;
|
|
53328
|
+
}
|
|
53329
|
+
}
|
|
53330
|
+
if (!closed) {
|
|
53331
|
+
this.throwError('Unclosed quote after "' + str + '"');
|
|
53332
|
+
}
|
|
53333
|
+
return {
|
|
53334
|
+
type: Jsep.LITERAL,
|
|
53335
|
+
value: str,
|
|
53336
|
+
raw: this.expr.substring(startIndex, this.index)
|
|
53337
|
+
};
|
|
53338
|
+
}
|
|
53339
|
+
/**
|
|
53340
|
+
* Gobbles only identifiers
|
|
53341
|
+
* e.g.: `foo`, `_value`, `$x1`
|
|
53342
|
+
* Also, this function checks if that identifier is a literal:
|
|
53343
|
+
* (e.g. `true`, `false`, `null`) or `this`
|
|
53344
|
+
* @returns {jsep.Identifier}
|
|
53345
|
+
*/
|
|
53346
|
+
gobbleIdentifier() {
|
|
53347
|
+
let ch = this.code, start = this.index;
|
|
53348
|
+
if (Jsep.isIdentifierStart(ch)) {
|
|
53349
|
+
this.index++;
|
|
53350
|
+
} else {
|
|
53351
|
+
this.throwError("Unexpected " + this.char);
|
|
53352
|
+
}
|
|
53353
|
+
while (this.index < this.expr.length) {
|
|
53354
|
+
ch = this.code;
|
|
53355
|
+
if (Jsep.isIdentifierPart(ch)) {
|
|
53356
|
+
this.index++;
|
|
53357
|
+
} else {
|
|
53358
|
+
break;
|
|
53359
|
+
}
|
|
53360
|
+
}
|
|
53361
|
+
return {
|
|
53362
|
+
type: Jsep.IDENTIFIER,
|
|
53363
|
+
name: this.expr.slice(start, this.index)
|
|
53364
|
+
};
|
|
53365
|
+
}
|
|
53366
|
+
/**
|
|
53367
|
+
* Gobbles a list of arguments within the context of a function call
|
|
53368
|
+
* or array literal. This function also assumes that the opening character
|
|
53369
|
+
* `(` or `[` has already been gobbled, and gobbles expressions and commas
|
|
53370
|
+
* until the terminator character `)` or `]` is encountered.
|
|
53371
|
+
* e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`
|
|
53372
|
+
* @param {number} termination
|
|
53373
|
+
* @returns {jsep.Expression[]}
|
|
53374
|
+
*/
|
|
53375
|
+
gobbleArguments(termination) {
|
|
53376
|
+
const args = [];
|
|
53377
|
+
let closed = false;
|
|
53378
|
+
let separator_count = 0;
|
|
53379
|
+
while (this.index < this.expr.length) {
|
|
53380
|
+
this.gobbleSpaces();
|
|
53381
|
+
let ch_i = this.code;
|
|
53382
|
+
if (ch_i === termination) {
|
|
53383
|
+
closed = true;
|
|
53384
|
+
this.index++;
|
|
53385
|
+
if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
|
|
53386
|
+
this.throwError("Unexpected token " + String.fromCharCode(termination));
|
|
53387
|
+
}
|
|
53388
|
+
break;
|
|
53389
|
+
} else if (ch_i === Jsep.COMMA_CODE) {
|
|
53390
|
+
this.index++;
|
|
53391
|
+
separator_count++;
|
|
53392
|
+
if (separator_count !== args.length) {
|
|
53393
|
+
if (termination === Jsep.CPAREN_CODE) {
|
|
53394
|
+
this.throwError("Unexpected token ,");
|
|
53395
|
+
} else if (termination === Jsep.CBRACK_CODE) {
|
|
53396
|
+
for (let arg = args.length; arg < separator_count; arg++) {
|
|
53397
|
+
args.push(null);
|
|
53398
|
+
}
|
|
53399
|
+
}
|
|
53400
|
+
}
|
|
53401
|
+
} else if (args.length !== separator_count && separator_count !== 0) {
|
|
53402
|
+
this.throwError("Expected comma");
|
|
53403
|
+
} else {
|
|
53404
|
+
const node = this.gobbleExpression();
|
|
53405
|
+
if (!node || node.type === Jsep.COMPOUND) {
|
|
53406
|
+
this.throwError("Expected comma");
|
|
53407
|
+
}
|
|
53408
|
+
args.push(node);
|
|
53409
|
+
}
|
|
53410
|
+
}
|
|
53411
|
+
if (!closed) {
|
|
53412
|
+
this.throwError("Expected " + String.fromCharCode(termination));
|
|
53413
|
+
}
|
|
53414
|
+
return args;
|
|
53415
|
+
}
|
|
53416
|
+
/**
|
|
53417
|
+
* Responsible for parsing a group of things within parentheses `()`
|
|
53418
|
+
* that have no identifier in front (so not a function call)
|
|
53419
|
+
* This function assumes that it needs to gobble the opening parenthesis
|
|
53420
|
+
* and then tries to gobble everything within that parenthesis, assuming
|
|
53421
|
+
* that the next thing it should see is the close parenthesis. If not,
|
|
53422
|
+
* then the expression probably doesn't have a `)`
|
|
53423
|
+
* @returns {boolean|jsep.Expression}
|
|
53424
|
+
*/
|
|
53425
|
+
gobbleGroup() {
|
|
53426
|
+
this.index++;
|
|
53427
|
+
let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
|
|
53428
|
+
if (this.code === Jsep.CPAREN_CODE) {
|
|
53429
|
+
this.index++;
|
|
53430
|
+
if (nodes.length === 1) {
|
|
53431
|
+
return nodes[0];
|
|
53432
|
+
} else if (!nodes.length) {
|
|
53433
|
+
return false;
|
|
53434
|
+
} else {
|
|
53435
|
+
return {
|
|
53436
|
+
type: Jsep.SEQUENCE_EXP,
|
|
53437
|
+
expressions: nodes
|
|
53438
|
+
};
|
|
53439
|
+
}
|
|
53440
|
+
} else {
|
|
53441
|
+
this.throwError("Unclosed (");
|
|
53442
|
+
}
|
|
53443
|
+
}
|
|
53444
|
+
/**
|
|
53445
|
+
* Responsible for parsing Array literals `[1, 2, 3]`
|
|
53446
|
+
* This function assumes that it needs to gobble the opening bracket
|
|
53447
|
+
* and then tries to gobble the expressions as arguments.
|
|
53448
|
+
* @returns {jsep.ArrayExpression}
|
|
53449
|
+
*/
|
|
53450
|
+
gobbleArray() {
|
|
53451
|
+
this.index++;
|
|
53452
|
+
return {
|
|
53453
|
+
type: Jsep.ARRAY_EXP,
|
|
53454
|
+
elements: this.gobbleArguments(Jsep.CBRACK_CODE)
|
|
53455
|
+
};
|
|
53456
|
+
}
|
|
53457
|
+
}
|
|
53458
|
+
const hooks = new Hooks();
|
|
53459
|
+
Object.assign(Jsep, {
|
|
53460
|
+
hooks,
|
|
53461
|
+
plugins: new Plugins(Jsep),
|
|
53462
|
+
// Node Types
|
|
53463
|
+
// ----------
|
|
53464
|
+
// This is the full set of types that any JSEP node can be.
|
|
53465
|
+
// Store them here to save space when minified
|
|
53466
|
+
COMPOUND: "Compound",
|
|
53467
|
+
SEQUENCE_EXP: "SequenceExpression",
|
|
53468
|
+
IDENTIFIER: "Identifier",
|
|
53469
|
+
MEMBER_EXP: "MemberExpression",
|
|
53470
|
+
LITERAL: "Literal",
|
|
53471
|
+
THIS_EXP: "ThisExpression",
|
|
53472
|
+
CALL_EXP: "CallExpression",
|
|
53473
|
+
UNARY_EXP: "UnaryExpression",
|
|
53474
|
+
BINARY_EXP: "BinaryExpression",
|
|
53475
|
+
ARRAY_EXP: "ArrayExpression",
|
|
53476
|
+
TAB_CODE: 9,
|
|
53477
|
+
LF_CODE: 10,
|
|
53478
|
+
CR_CODE: 13,
|
|
53479
|
+
SPACE_CODE: 32,
|
|
53480
|
+
PERIOD_CODE: 46,
|
|
53481
|
+
// '.'
|
|
53482
|
+
COMMA_CODE: 44,
|
|
53483
|
+
// ','
|
|
53484
|
+
SQUOTE_CODE: 39,
|
|
53485
|
+
// single quote
|
|
53486
|
+
DQUOTE_CODE: 34,
|
|
53487
|
+
// double quotes
|
|
53488
|
+
OPAREN_CODE: 40,
|
|
53489
|
+
// (
|
|
53490
|
+
CPAREN_CODE: 41,
|
|
53491
|
+
// )
|
|
53492
|
+
OBRACK_CODE: 91,
|
|
53493
|
+
// [
|
|
53494
|
+
CBRACK_CODE: 93,
|
|
53495
|
+
// ]
|
|
53496
|
+
QUMARK_CODE: 63,
|
|
53497
|
+
// ?
|
|
53498
|
+
SEMCOL_CODE: 59,
|
|
53499
|
+
// ;
|
|
53500
|
+
COLON_CODE: 58,
|
|
53501
|
+
// :
|
|
53502
|
+
// Operations
|
|
53503
|
+
// ----------
|
|
53504
|
+
// Use a quickly-accessible map to store all of the unary operators
|
|
53505
|
+
// Values are set to `1` (it really doesn't matter)
|
|
53506
|
+
unary_ops: {
|
|
53507
|
+
"-": 1,
|
|
53508
|
+
"!": 1,
|
|
53509
|
+
"~": 1,
|
|
53510
|
+
"+": 1
|
|
53511
|
+
},
|
|
53512
|
+
// Also use a map for the binary operations but set their values to their
|
|
53513
|
+
// binary precedence for quick reference (higher number = higher precedence)
|
|
53514
|
+
// see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
|
|
53515
|
+
binary_ops: {
|
|
53516
|
+
"||": 1,
|
|
53517
|
+
"??": 1,
|
|
53518
|
+
"&&": 2,
|
|
53519
|
+
"|": 3,
|
|
53520
|
+
"^": 4,
|
|
53521
|
+
"&": 5,
|
|
53522
|
+
"==": 6,
|
|
53523
|
+
"!=": 6,
|
|
53524
|
+
"===": 6,
|
|
53525
|
+
"!==": 6,
|
|
53526
|
+
"<": 7,
|
|
53527
|
+
">": 7,
|
|
53528
|
+
"<=": 7,
|
|
53529
|
+
">=": 7,
|
|
53530
|
+
"<<": 8,
|
|
53531
|
+
">>": 8,
|
|
53532
|
+
">>>": 8,
|
|
53533
|
+
"+": 9,
|
|
53534
|
+
"-": 9,
|
|
53535
|
+
"*": 10,
|
|
53536
|
+
"/": 10,
|
|
53537
|
+
"%": 10,
|
|
53538
|
+
"**": 11
|
|
53539
|
+
},
|
|
53540
|
+
// sets specific binary_ops as right-associative
|
|
53541
|
+
right_associative: /* @__PURE__ */ new Set(["**"]),
|
|
53542
|
+
// Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)
|
|
53543
|
+
additional_identifier_chars: /* @__PURE__ */ new Set(["$", "_"]),
|
|
53544
|
+
// Literals
|
|
53545
|
+
// ----------
|
|
53546
|
+
// Store the values to return for the various literals we may encounter
|
|
53547
|
+
literals: {
|
|
53548
|
+
"true": true,
|
|
53549
|
+
"false": false,
|
|
53550
|
+
"null": null
|
|
53551
|
+
},
|
|
53552
|
+
// Except for `this`, which is special. This could be changed to something like `'self'` as well
|
|
53553
|
+
this_str: "this"
|
|
53554
|
+
});
|
|
53555
|
+
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
53556
|
+
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
53557
|
+
const jsep = (expr) => new Jsep(expr).parse();
|
|
53558
|
+
const stdClassProps = Object.getOwnPropertyNames(class Test {
|
|
53559
|
+
});
|
|
53560
|
+
Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === void 0).forEach((m) => {
|
|
53561
|
+
jsep[m] = Jsep[m];
|
|
53562
|
+
});
|
|
53563
|
+
jsep.Jsep = Jsep;
|
|
53564
|
+
const CONDITIONAL_EXP = "ConditionalExpression";
|
|
53565
|
+
var ternary = {
|
|
53566
|
+
name: "ternary",
|
|
53567
|
+
init(jsep2) {
|
|
53568
|
+
jsep2.hooks.add("after-expression", function gobbleTernary(env) {
|
|
53569
|
+
if (env.node && this.code === jsep2.QUMARK_CODE) {
|
|
53570
|
+
this.index++;
|
|
53571
|
+
const test2 = env.node;
|
|
53572
|
+
const consequent = this.gobbleExpression();
|
|
53573
|
+
if (!consequent) {
|
|
53574
|
+
this.throwError("Expected expression");
|
|
53575
|
+
}
|
|
53576
|
+
this.gobbleSpaces();
|
|
53577
|
+
if (this.code === jsep2.COLON_CODE) {
|
|
53578
|
+
this.index++;
|
|
53579
|
+
const alternate = this.gobbleExpression();
|
|
53580
|
+
if (!alternate) {
|
|
53581
|
+
this.throwError("Expected expression");
|
|
53582
|
+
}
|
|
53583
|
+
env.node = {
|
|
53584
|
+
type: CONDITIONAL_EXP,
|
|
53585
|
+
test: test2,
|
|
53586
|
+
consequent,
|
|
53587
|
+
alternate
|
|
53588
|
+
};
|
|
53589
|
+
if (test2.operator && jsep2.binary_ops[test2.operator] <= 0.9) {
|
|
53590
|
+
let newTest = test2;
|
|
53591
|
+
while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
|
|
53592
|
+
newTest = newTest.right;
|
|
53593
|
+
}
|
|
53594
|
+
env.node.test = newTest.right;
|
|
53595
|
+
newTest.right = env.node;
|
|
53596
|
+
env.node = test2;
|
|
53597
|
+
}
|
|
53598
|
+
} else {
|
|
53599
|
+
this.throwError("Expected :");
|
|
53600
|
+
}
|
|
53601
|
+
}
|
|
53602
|
+
});
|
|
53603
|
+
}
|
|
53604
|
+
};
|
|
53605
|
+
jsep.plugins.register(ternary);
|
|
53606
|
+
const FSLASH_CODE = 47;
|
|
53607
|
+
const BSLASH_CODE = 92;
|
|
53608
|
+
var index = {
|
|
53609
|
+
name: "regex",
|
|
53610
|
+
init(jsep2) {
|
|
53611
|
+
jsep2.hooks.add("gobble-token", function gobbleRegexLiteral(env) {
|
|
53612
|
+
if (this.code === FSLASH_CODE) {
|
|
53613
|
+
const patternIndex = ++this.index;
|
|
53614
|
+
let inCharSet = false;
|
|
53615
|
+
while (this.index < this.expr.length) {
|
|
53616
|
+
if (this.code === FSLASH_CODE && !inCharSet) {
|
|
53617
|
+
const pattern4 = this.expr.slice(patternIndex, this.index);
|
|
53618
|
+
let flags = "";
|
|
53619
|
+
while (++this.index < this.expr.length) {
|
|
53620
|
+
const code = this.code;
|
|
53621
|
+
if (code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57) {
|
|
53622
|
+
flags += this.char;
|
|
53623
|
+
} else {
|
|
53624
|
+
break;
|
|
53625
|
+
}
|
|
53626
|
+
}
|
|
53627
|
+
let value;
|
|
53628
|
+
try {
|
|
53629
|
+
value = new RegExp(pattern4, flags);
|
|
53630
|
+
} catch (e) {
|
|
53631
|
+
this.throwError(e.message);
|
|
53632
|
+
}
|
|
53633
|
+
env.node = {
|
|
53634
|
+
type: jsep2.LITERAL,
|
|
53635
|
+
value,
|
|
53636
|
+
raw: this.expr.slice(patternIndex - 1, this.index)
|
|
53637
|
+
};
|
|
53638
|
+
env.node = this.gobbleTokenProperty(env.node);
|
|
53639
|
+
return env.node;
|
|
53640
|
+
}
|
|
53641
|
+
if (this.code === jsep2.OBRACK_CODE) {
|
|
53642
|
+
inCharSet = true;
|
|
53643
|
+
} else if (inCharSet && this.code === jsep2.CBRACK_CODE) {
|
|
53644
|
+
inCharSet = false;
|
|
53645
|
+
}
|
|
53646
|
+
this.index += this.code === BSLASH_CODE ? 2 : 1;
|
|
53647
|
+
}
|
|
53648
|
+
this.throwError("Unclosed Regex");
|
|
53649
|
+
}
|
|
53650
|
+
});
|
|
53651
|
+
}
|
|
53652
|
+
};
|
|
53653
|
+
const PLUS_CODE = 43;
|
|
53654
|
+
const MINUS_CODE = 45;
|
|
53655
|
+
const plugin = {
|
|
53656
|
+
name: "assignment",
|
|
53657
|
+
assignmentOperators: /* @__PURE__ */ new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
53658
|
+
updateOperators: [PLUS_CODE, MINUS_CODE],
|
|
53659
|
+
assignmentPrecedence: 0.9,
|
|
53660
|
+
init(jsep2) {
|
|
53661
|
+
const updateNodeTypes = [jsep2.IDENTIFIER, jsep2.MEMBER_EXP];
|
|
53662
|
+
plugin.assignmentOperators.forEach((op) => jsep2.addBinaryOp(op, plugin.assignmentPrecedence, true));
|
|
53663
|
+
jsep2.hooks.add("gobble-token", function gobbleUpdatePrefix(env) {
|
|
53664
|
+
const code = this.code;
|
|
53665
|
+
if (plugin.updateOperators.some((c2) => c2 === code && c2 === this.expr.charCodeAt(this.index + 1))) {
|
|
53666
|
+
this.index += 2;
|
|
53667
|
+
env.node = {
|
|
53668
|
+
type: "UpdateExpression",
|
|
53669
|
+
operator: code === PLUS_CODE ? "++" : "--",
|
|
53670
|
+
argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
|
|
53671
|
+
prefix: true
|
|
53672
|
+
};
|
|
53673
|
+
if (!env.node.argument || !updateNodeTypes.includes(env.node.argument.type)) {
|
|
53674
|
+
this.throwError(`Unexpected ${env.node.operator}`);
|
|
53675
|
+
}
|
|
53676
|
+
}
|
|
53677
|
+
});
|
|
53678
|
+
jsep2.hooks.add("after-token", function gobbleUpdatePostfix(env) {
|
|
53679
|
+
if (env.node) {
|
|
53680
|
+
const code = this.code;
|
|
53681
|
+
if (plugin.updateOperators.some((c2) => c2 === code && c2 === this.expr.charCodeAt(this.index + 1))) {
|
|
53682
|
+
if (!updateNodeTypes.includes(env.node.type)) {
|
|
53683
|
+
this.throwError(`Unexpected ${env.node.operator}`);
|
|
53684
|
+
}
|
|
53685
|
+
this.index += 2;
|
|
53686
|
+
env.node = {
|
|
53687
|
+
type: "UpdateExpression",
|
|
53688
|
+
operator: code === PLUS_CODE ? "++" : "--",
|
|
53689
|
+
argument: env.node,
|
|
53690
|
+
prefix: false
|
|
53691
|
+
};
|
|
53692
|
+
}
|
|
53693
|
+
}
|
|
53694
|
+
});
|
|
53695
|
+
jsep2.hooks.add("after-expression", function gobbleAssignment(env) {
|
|
53696
|
+
if (env.node) {
|
|
53697
|
+
updateBinariesToAssignments(env.node);
|
|
53698
|
+
}
|
|
53699
|
+
});
|
|
53700
|
+
function updateBinariesToAssignments(node) {
|
|
53701
|
+
if (plugin.assignmentOperators.has(node.operator)) {
|
|
53702
|
+
node.type = "AssignmentExpression";
|
|
53703
|
+
updateBinariesToAssignments(node.left);
|
|
53704
|
+
updateBinariesToAssignments(node.right);
|
|
53705
|
+
} else if (!node.operator) {
|
|
53706
|
+
Object.values(node).forEach((val) => {
|
|
53707
|
+
if (val && typeof val === "object") {
|
|
53708
|
+
updateBinariesToAssignments(val);
|
|
53709
|
+
}
|
|
53710
|
+
});
|
|
53711
|
+
}
|
|
53712
|
+
}
|
|
53713
|
+
}
|
|
53714
|
+
};
|
|
53715
|
+
jsep.plugins.register(index, plugin);
|
|
53716
|
+
jsep.addUnaryOp("typeof");
|
|
53717
|
+
jsep.addUnaryOp("void");
|
|
53718
|
+
jsep.addLiteral("null", null);
|
|
53719
|
+
jsep.addLiteral("undefined", void 0);
|
|
53720
|
+
const BLOCKED_PROTO_PROPERTIES = /* @__PURE__ */ new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
53721
|
+
const SafeEval = {
|
|
53722
|
+
/**
|
|
53723
|
+
* @param {jsep.Expression} ast
|
|
53724
|
+
* @param {Record<string, any>} subs
|
|
53725
|
+
*/
|
|
53726
|
+
evalAst(ast, subs) {
|
|
53727
|
+
switch (ast.type) {
|
|
53728
|
+
case "BinaryExpression":
|
|
53729
|
+
case "LogicalExpression":
|
|
53730
|
+
return SafeEval.evalBinaryExpression(ast, subs);
|
|
53731
|
+
case "Compound":
|
|
53732
|
+
return SafeEval.evalCompound(ast, subs);
|
|
53733
|
+
case "ConditionalExpression":
|
|
53734
|
+
return SafeEval.evalConditionalExpression(ast, subs);
|
|
53735
|
+
case "Identifier":
|
|
53736
|
+
return SafeEval.evalIdentifier(ast, subs);
|
|
53737
|
+
case "Literal":
|
|
53738
|
+
return SafeEval.evalLiteral(ast, subs);
|
|
53739
|
+
case "MemberExpression":
|
|
53740
|
+
return SafeEval.evalMemberExpression(ast, subs);
|
|
53741
|
+
case "UnaryExpression":
|
|
53742
|
+
return SafeEval.evalUnaryExpression(ast, subs);
|
|
53743
|
+
case "ArrayExpression":
|
|
53744
|
+
return SafeEval.evalArrayExpression(ast, subs);
|
|
53745
|
+
case "CallExpression":
|
|
53746
|
+
return SafeEval.evalCallExpression(ast, subs);
|
|
53747
|
+
case "AssignmentExpression":
|
|
53748
|
+
return SafeEval.evalAssignmentExpression(ast, subs);
|
|
53749
|
+
default:
|
|
53750
|
+
throw SyntaxError("Unexpected expression", ast);
|
|
53751
|
+
}
|
|
53752
|
+
},
|
|
53753
|
+
evalBinaryExpression(ast, subs) {
|
|
53754
|
+
const result = {
|
|
53755
|
+
"||": (a, b2) => a || b2(),
|
|
53756
|
+
"&&": (a, b2) => a && b2(),
|
|
53757
|
+
"|": (a, b2) => a | b2(),
|
|
53758
|
+
"^": (a, b2) => a ^ b2(),
|
|
53759
|
+
"&": (a, b2) => a & b2(),
|
|
53760
|
+
// eslint-disable-next-line eqeqeq -- API
|
|
53761
|
+
"==": (a, b2) => a == b2(),
|
|
53762
|
+
// eslint-disable-next-line eqeqeq -- API
|
|
53763
|
+
"!=": (a, b2) => a != b2(),
|
|
53764
|
+
"===": (a, b2) => a === b2(),
|
|
53765
|
+
"!==": (a, b2) => a !== b2(),
|
|
53766
|
+
"<": (a, b2) => a < b2(),
|
|
53767
|
+
">": (a, b2) => a > b2(),
|
|
53768
|
+
"<=": (a, b2) => a <= b2(),
|
|
53769
|
+
">=": (a, b2) => a >= b2(),
|
|
53770
|
+
"<<": (a, b2) => a << b2(),
|
|
53771
|
+
">>": (a, b2) => a >> b2(),
|
|
53772
|
+
">>>": (a, b2) => a >>> b2(),
|
|
53773
|
+
"+": (a, b2) => a + b2(),
|
|
53774
|
+
"-": (a, b2) => a - b2(),
|
|
53775
|
+
"*": (a, b2) => a * b2(),
|
|
53776
|
+
"/": (a, b2) => a / b2(),
|
|
53777
|
+
"%": (a, b2) => a % b2()
|
|
53778
|
+
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
|
|
53779
|
+
return result;
|
|
53780
|
+
},
|
|
53781
|
+
evalCompound(ast, subs) {
|
|
53782
|
+
let last2;
|
|
53783
|
+
for (let i = 0; i < ast.body.length; i++) {
|
|
53784
|
+
if (ast.body[i].type === "Identifier" && ["var", "let", "const"].includes(ast.body[i].name) && ast.body[i + 1] && ast.body[i + 1].type === "AssignmentExpression") {
|
|
53785
|
+
i += 1;
|
|
53786
|
+
}
|
|
53787
|
+
const expr = ast.body[i];
|
|
53788
|
+
last2 = SafeEval.evalAst(expr, subs);
|
|
53789
|
+
}
|
|
53790
|
+
return last2;
|
|
53791
|
+
},
|
|
53792
|
+
evalConditionalExpression(ast, subs) {
|
|
53793
|
+
if (SafeEval.evalAst(ast.test, subs)) {
|
|
53794
|
+
return SafeEval.evalAst(ast.consequent, subs);
|
|
53795
|
+
}
|
|
53796
|
+
return SafeEval.evalAst(ast.alternate, subs);
|
|
53797
|
+
},
|
|
53798
|
+
evalIdentifier(ast, subs) {
|
|
53799
|
+
if (Object.hasOwn(subs, ast.name)) {
|
|
53800
|
+
return subs[ast.name];
|
|
53801
|
+
}
|
|
53802
|
+
throw ReferenceError(`${ast.name} is not defined`);
|
|
53803
|
+
},
|
|
53804
|
+
evalLiteral(ast) {
|
|
53805
|
+
return ast.value;
|
|
53806
|
+
},
|
|
53807
|
+
evalMemberExpression(ast, subs) {
|
|
53808
|
+
const prop = String(
|
|
53809
|
+
// NOTE: `String(value)` throws error when
|
|
53810
|
+
// value has overwritten the toString method to return non-string
|
|
53811
|
+
// i.e. `value = {toString: () => []}`
|
|
53812
|
+
ast.computed ? SafeEval.evalAst(ast.property) : ast.property.name
|
|
53813
|
+
// `object.property` property is Identifier
|
|
53814
|
+
);
|
|
53815
|
+
const obj = SafeEval.evalAst(ast.object, subs);
|
|
53816
|
+
if (obj === void 0 || obj === null) {
|
|
53817
|
+
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
53818
|
+
}
|
|
53819
|
+
if (!Object.hasOwn(obj, prop) && BLOCKED_PROTO_PROPERTIES.has(prop)) {
|
|
53820
|
+
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
53821
|
+
}
|
|
53822
|
+
const result = obj[prop];
|
|
53823
|
+
if (typeof result === "function") {
|
|
53824
|
+
return result.bind(obj);
|
|
53825
|
+
}
|
|
53826
|
+
return result;
|
|
53827
|
+
},
|
|
53828
|
+
evalUnaryExpression(ast, subs) {
|
|
53829
|
+
const result = {
|
|
53830
|
+
"-": (a) => -SafeEval.evalAst(a, subs),
|
|
53831
|
+
"!": (a) => !SafeEval.evalAst(a, subs),
|
|
53832
|
+
"~": (a) => ~SafeEval.evalAst(a, subs),
|
|
53833
|
+
// eslint-disable-next-line no-implicit-coercion -- API
|
|
53834
|
+
"+": (a) => +SafeEval.evalAst(a, subs),
|
|
53835
|
+
typeof: (a) => typeof SafeEval.evalAst(a, subs),
|
|
53836
|
+
// eslint-disable-next-line no-void, sonarjs/void-use -- feature
|
|
53837
|
+
void: (a) => void SafeEval.evalAst(a, subs)
|
|
53838
|
+
}[ast.operator](ast.argument);
|
|
53839
|
+
return result;
|
|
53840
|
+
},
|
|
53841
|
+
evalArrayExpression(ast, subs) {
|
|
53842
|
+
return ast.elements.map((el) => SafeEval.evalAst(el, subs));
|
|
53843
|
+
},
|
|
53844
|
+
evalCallExpression(ast, subs) {
|
|
53845
|
+
const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
|
|
53846
|
+
const func = SafeEval.evalAst(ast.callee, subs);
|
|
53847
|
+
if (func === Function) {
|
|
53848
|
+
throw new Error("Function constructor is disabled");
|
|
53849
|
+
}
|
|
53850
|
+
return func(...args);
|
|
53851
|
+
},
|
|
53852
|
+
evalAssignmentExpression(ast, subs) {
|
|
53853
|
+
if (ast.left.type !== "Identifier") {
|
|
53854
|
+
throw SyntaxError("Invalid left-hand side in assignment");
|
|
53855
|
+
}
|
|
53856
|
+
const id = ast.left.name;
|
|
53857
|
+
const value = SafeEval.evalAst(ast.right, subs);
|
|
53858
|
+
subs[id] = value;
|
|
53859
|
+
return subs[id];
|
|
53860
|
+
}
|
|
53861
|
+
};
|
|
53862
|
+
class SafeScript {
|
|
53863
|
+
/**
|
|
53864
|
+
* @param {string} expr Expression to evaluate
|
|
53865
|
+
*/
|
|
53866
|
+
constructor(expr) {
|
|
53867
|
+
this.code = expr;
|
|
53868
|
+
this.ast = jsep(this.code);
|
|
53869
|
+
}
|
|
53870
|
+
/**
|
|
53871
|
+
* @param {object} context Object whose items will be added
|
|
53872
|
+
* to evaluation
|
|
53873
|
+
* @returns {EvaluatedResult} Result of evaluated code
|
|
53874
|
+
*/
|
|
53875
|
+
runInNewContext(context) {
|
|
53876
|
+
const keyMap = Object.assign(/* @__PURE__ */ Object.create(null), context);
|
|
53877
|
+
return SafeEval.evalAst(this.ast, keyMap);
|
|
53878
|
+
}
|
|
53879
|
+
}
|
|
53880
|
+
function push(arr, item) {
|
|
53881
|
+
arr = arr.slice();
|
|
53882
|
+
arr.push(item);
|
|
53883
|
+
return arr;
|
|
53884
|
+
}
|
|
53885
|
+
function unshift(item, arr) {
|
|
53886
|
+
arr = arr.slice();
|
|
53887
|
+
arr.unshift(item);
|
|
53888
|
+
return arr;
|
|
53889
|
+
}
|
|
53890
|
+
class NewError extends Error {
|
|
53891
|
+
/**
|
|
53892
|
+
* @param {AnyResult} value The evaluated scalar value
|
|
53893
|
+
*/
|
|
53894
|
+
constructor(value) {
|
|
53895
|
+
super('JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)');
|
|
53896
|
+
this.avoidNew = true;
|
|
53897
|
+
this.value = value;
|
|
53898
|
+
this.name = "NewError";
|
|
53899
|
+
}
|
|
53900
|
+
}
|
|
53901
|
+
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
|
|
53902
|
+
if (!(this instanceof JSONPath)) {
|
|
53903
|
+
try {
|
|
53904
|
+
return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
|
|
53905
|
+
} catch (e) {
|
|
53906
|
+
if (!e.avoidNew) {
|
|
53907
|
+
throw e;
|
|
53908
|
+
}
|
|
53909
|
+
return e.value;
|
|
53910
|
+
}
|
|
53911
|
+
}
|
|
53912
|
+
if (typeof opts === "string") {
|
|
53913
|
+
otherTypeCallback = callback;
|
|
53914
|
+
callback = obj;
|
|
53915
|
+
obj = expr;
|
|
53916
|
+
expr = opts;
|
|
53917
|
+
opts = null;
|
|
53918
|
+
}
|
|
53919
|
+
const optObj = opts && typeof opts === "object";
|
|
53920
|
+
opts = opts || {};
|
|
53921
|
+
this.json = opts.json || obj;
|
|
53922
|
+
this.path = opts.path || expr;
|
|
53923
|
+
this.resultType = opts.resultType || "value";
|
|
53924
|
+
this.flatten = opts.flatten || false;
|
|
53925
|
+
this.wrap = Object.hasOwn(opts, "wrap") ? opts.wrap : true;
|
|
53926
|
+
this.sandbox = opts.sandbox || {};
|
|
53927
|
+
this.eval = opts.eval === void 0 ? "safe" : opts.eval;
|
|
53928
|
+
this.ignoreEvalErrors = typeof opts.ignoreEvalErrors === "undefined" ? false : opts.ignoreEvalErrors;
|
|
53929
|
+
this.parent = opts.parent || null;
|
|
53930
|
+
this.parentProperty = opts.parentProperty || null;
|
|
53931
|
+
this.callback = opts.callback || callback || null;
|
|
53932
|
+
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function() {
|
|
53933
|
+
throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.");
|
|
53934
|
+
};
|
|
53935
|
+
if (opts.autostart !== false) {
|
|
53936
|
+
const args = {
|
|
53937
|
+
path: optObj ? opts.path : expr
|
|
53938
|
+
};
|
|
53939
|
+
if (!optObj) {
|
|
53940
|
+
args.json = obj;
|
|
53941
|
+
} else if ("json" in opts) {
|
|
53942
|
+
args.json = opts.json;
|
|
53943
|
+
}
|
|
53944
|
+
const ret = this.evaluate(args);
|
|
53945
|
+
if (!ret || typeof ret !== "object") {
|
|
53946
|
+
throw new NewError(ret);
|
|
53947
|
+
}
|
|
53948
|
+
return ret;
|
|
53949
|
+
}
|
|
53950
|
+
}
|
|
53951
|
+
JSONPath.prototype.evaluate = function(expr, json, callback, otherTypeCallback) {
|
|
53952
|
+
let currParent = this.parent, currParentProperty = this.parentProperty;
|
|
53953
|
+
let {
|
|
53954
|
+
flatten: flatten2,
|
|
53955
|
+
wrap
|
|
53956
|
+
} = this;
|
|
53957
|
+
this.currResultType = this.resultType;
|
|
53958
|
+
this.currEval = this.eval;
|
|
53959
|
+
this.currSandbox = this.sandbox;
|
|
53960
|
+
callback = callback || this.callback;
|
|
53961
|
+
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
53962
|
+
json = json || this.json;
|
|
53963
|
+
expr = expr || this.path;
|
|
53964
|
+
if (expr && typeof expr === "object" && !Array.isArray(expr)) {
|
|
53965
|
+
if (!expr.path && expr.path !== "") {
|
|
53966
|
+
throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');
|
|
53967
|
+
}
|
|
53968
|
+
if (!Object.hasOwn(expr, "json")) {
|
|
53969
|
+
throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');
|
|
53970
|
+
}
|
|
53971
|
+
({
|
|
53972
|
+
json
|
|
53973
|
+
} = expr);
|
|
53974
|
+
flatten2 = Object.hasOwn(expr, "flatten") ? expr.flatten : flatten2;
|
|
53975
|
+
this.currResultType = Object.hasOwn(expr, "resultType") ? expr.resultType : this.currResultType;
|
|
53976
|
+
this.currSandbox = Object.hasOwn(expr, "sandbox") ? expr.sandbox : this.currSandbox;
|
|
53977
|
+
wrap = Object.hasOwn(expr, "wrap") ? expr.wrap : wrap;
|
|
53978
|
+
this.currEval = Object.hasOwn(expr, "eval") ? expr.eval : this.currEval;
|
|
53979
|
+
callback = Object.hasOwn(expr, "callback") ? expr.callback : callback;
|
|
53980
|
+
this.currOtherTypeCallback = Object.hasOwn(expr, "otherTypeCallback") ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
53981
|
+
currParent = Object.hasOwn(expr, "parent") ? expr.parent : currParent;
|
|
53982
|
+
currParentProperty = Object.hasOwn(expr, "parentProperty") ? expr.parentProperty : currParentProperty;
|
|
53983
|
+
expr = expr.path;
|
|
53984
|
+
}
|
|
53985
|
+
currParent = currParent || null;
|
|
53986
|
+
currParentProperty = currParentProperty || null;
|
|
53987
|
+
if (Array.isArray(expr)) {
|
|
53988
|
+
expr = JSONPath.toPathString(expr);
|
|
53989
|
+
}
|
|
53990
|
+
if (!expr && expr !== "" || !json) {
|
|
53991
|
+
return void 0;
|
|
53992
|
+
}
|
|
53993
|
+
const exprList = JSONPath.toPathArray(expr);
|
|
53994
|
+
if (exprList[0] === "$" && exprList.length > 1) {
|
|
53995
|
+
exprList.shift();
|
|
53996
|
+
}
|
|
53997
|
+
this._hasParentSelector = null;
|
|
53998
|
+
const result = this._trace(exprList, json, ["$"], currParent, currParentProperty, callback).filter(function(ea2) {
|
|
53999
|
+
return ea2 && !ea2.isParentSelector;
|
|
54000
|
+
});
|
|
54001
|
+
if (!result.length) {
|
|
54002
|
+
return wrap ? [] : void 0;
|
|
54003
|
+
}
|
|
54004
|
+
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
|
|
54005
|
+
return this._getPreferredOutput(result[0]);
|
|
54006
|
+
}
|
|
54007
|
+
return result.reduce((rslt, ea2) => {
|
|
54008
|
+
const valOrPath = this._getPreferredOutput(ea2);
|
|
54009
|
+
if (flatten2 && Array.isArray(valOrPath)) {
|
|
54010
|
+
rslt = rslt.concat(valOrPath);
|
|
54011
|
+
} else {
|
|
54012
|
+
rslt.push(valOrPath);
|
|
54013
|
+
}
|
|
54014
|
+
return rslt;
|
|
54015
|
+
}, []);
|
|
54016
|
+
};
|
|
54017
|
+
JSONPath.prototype._getPreferredOutput = function(ea2) {
|
|
54018
|
+
const resultType = this.currResultType;
|
|
54019
|
+
switch (resultType) {
|
|
54020
|
+
case "all": {
|
|
54021
|
+
const path2 = Array.isArray(ea2.path) ? ea2.path : JSONPath.toPathArray(ea2.path);
|
|
54022
|
+
ea2.pointer = JSONPath.toPointer(path2);
|
|
54023
|
+
ea2.path = typeof ea2.path === "string" ? ea2.path : JSONPath.toPathString(ea2.path);
|
|
54024
|
+
return ea2;
|
|
54025
|
+
}
|
|
54026
|
+
case "value":
|
|
54027
|
+
case "parent":
|
|
54028
|
+
case "parentProperty":
|
|
54029
|
+
return ea2[resultType];
|
|
54030
|
+
case "path":
|
|
54031
|
+
return JSONPath.toPathString(ea2[resultType]);
|
|
54032
|
+
case "pointer":
|
|
54033
|
+
return JSONPath.toPointer(ea2.path);
|
|
54034
|
+
default:
|
|
54035
|
+
throw new TypeError("Unknown result type");
|
|
54036
|
+
}
|
|
54037
|
+
};
|
|
54038
|
+
JSONPath.prototype._handleCallback = function(fullRetObj, callback, type4) {
|
|
54039
|
+
if (callback) {
|
|
54040
|
+
const preferredOutput = this._getPreferredOutput(fullRetObj);
|
|
54041
|
+
fullRetObj.path = typeof fullRetObj.path === "string" ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
|
|
54042
|
+
callback(preferredOutput, type4, fullRetObj);
|
|
54043
|
+
}
|
|
54044
|
+
};
|
|
54045
|
+
JSONPath.prototype._trace = function(expr, val, path2, parent2, parentPropName, callback, hasArrExpr, literalPriority) {
|
|
54046
|
+
let retObj;
|
|
54047
|
+
if (!expr.length) {
|
|
54048
|
+
retObj = {
|
|
54049
|
+
path: path2,
|
|
54050
|
+
value: val,
|
|
54051
|
+
parent: parent2,
|
|
54052
|
+
parentProperty: parentPropName,
|
|
54053
|
+
hasArrExpr
|
|
54054
|
+
};
|
|
54055
|
+
this._handleCallback(retObj, callback, "value");
|
|
54056
|
+
return retObj;
|
|
54057
|
+
}
|
|
54058
|
+
const loc = expr[0], x2 = expr.slice(1);
|
|
54059
|
+
const ret = [];
|
|
54060
|
+
function addRet(elems) {
|
|
54061
|
+
if (Array.isArray(elems)) {
|
|
54062
|
+
elems.forEach((t) => {
|
|
54063
|
+
ret.push(t);
|
|
54064
|
+
});
|
|
54065
|
+
} else {
|
|
54066
|
+
ret.push(elems);
|
|
54067
|
+
}
|
|
54068
|
+
}
|
|
54069
|
+
if ((typeof loc !== "string" || literalPriority) && val && Object.hasOwn(val, loc)) {
|
|
54070
|
+
addRet(this._trace(x2, val[loc], push(path2, loc), val, loc, callback, hasArrExpr));
|
|
54071
|
+
} else if (loc === "*") {
|
|
54072
|
+
this._walk(val, (m) => {
|
|
54073
|
+
addRet(this._trace(x2, val[m], push(path2, m), val, m, callback, true, true));
|
|
54074
|
+
});
|
|
54075
|
+
} else if (loc === "..") {
|
|
54076
|
+
addRet(this._trace(x2, val, path2, parent2, parentPropName, callback, hasArrExpr));
|
|
54077
|
+
this._walk(val, (m) => {
|
|
54078
|
+
if (typeof val[m] === "object") {
|
|
54079
|
+
addRet(this._trace(expr.slice(), val[m], push(path2, m), val, m, callback, true));
|
|
54080
|
+
}
|
|
54081
|
+
});
|
|
54082
|
+
} else if (loc === "^") {
|
|
54083
|
+
this._hasParentSelector = true;
|
|
54084
|
+
return {
|
|
54085
|
+
path: path2.slice(0, -1),
|
|
54086
|
+
expr: x2,
|
|
54087
|
+
isParentSelector: true
|
|
54088
|
+
};
|
|
54089
|
+
} else if (loc === "~") {
|
|
54090
|
+
retObj = {
|
|
54091
|
+
path: push(path2, loc),
|
|
54092
|
+
value: parentPropName,
|
|
54093
|
+
parent: parent2,
|
|
54094
|
+
parentProperty: null
|
|
54095
|
+
};
|
|
54096
|
+
this._handleCallback(retObj, callback, "property");
|
|
54097
|
+
return retObj;
|
|
54098
|
+
} else if (loc === "$") {
|
|
54099
|
+
addRet(this._trace(x2, val, path2, null, null, callback, hasArrExpr));
|
|
54100
|
+
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
54101
|
+
addRet(this._slice(loc, x2, val, path2, parent2, parentPropName, callback));
|
|
54102
|
+
} else if (loc.indexOf("?(") === 0) {
|
|
54103
|
+
if (this.currEval === false) {
|
|
54104
|
+
throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
|
|
54105
|
+
}
|
|
54106
|
+
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, "$1");
|
|
54107
|
+
const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
|
|
54108
|
+
if (nested) {
|
|
54109
|
+
this._walk(val, (m) => {
|
|
54110
|
+
const npath = [nested[2]];
|
|
54111
|
+
const nvalue = nested[1] ? val[m][nested[1]] : val[m];
|
|
54112
|
+
const filterResults = this._trace(npath, nvalue, path2, parent2, parentPropName, callback, true);
|
|
54113
|
+
if (filterResults.length > 0) {
|
|
54114
|
+
addRet(this._trace(x2, val[m], push(path2, m), val, m, callback, true));
|
|
54115
|
+
}
|
|
54116
|
+
});
|
|
54117
|
+
} else {
|
|
54118
|
+
this._walk(val, (m) => {
|
|
54119
|
+
if (this._eval(safeLoc, val[m], m, path2, parent2, parentPropName)) {
|
|
54120
|
+
addRet(this._trace(x2, val[m], push(path2, m), val, m, callback, true));
|
|
54121
|
+
}
|
|
54122
|
+
});
|
|
54123
|
+
}
|
|
54124
|
+
} else if (loc[0] === "(") {
|
|
54125
|
+
if (this.currEval === false) {
|
|
54126
|
+
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
54127
|
+
}
|
|
54128
|
+
addRet(this._trace(unshift(this._eval(loc, val, path2.at(-1), path2.slice(0, -1), parent2, parentPropName), x2), val, path2, parent2, parentPropName, callback, hasArrExpr));
|
|
54129
|
+
} else if (loc[0] === "@") {
|
|
54130
|
+
let addType = false;
|
|
54131
|
+
const valueType = loc.slice(1, -2);
|
|
54132
|
+
switch (valueType) {
|
|
54133
|
+
case "scalar":
|
|
54134
|
+
if (!val || !["object", "function"].includes(typeof val)) {
|
|
54135
|
+
addType = true;
|
|
54136
|
+
}
|
|
54137
|
+
break;
|
|
54138
|
+
case "boolean":
|
|
54139
|
+
case "string":
|
|
54140
|
+
case "undefined":
|
|
54141
|
+
case "function":
|
|
54142
|
+
if (typeof val === valueType) {
|
|
54143
|
+
addType = true;
|
|
54144
|
+
}
|
|
54145
|
+
break;
|
|
54146
|
+
case "integer":
|
|
54147
|
+
if (Number.isFinite(val) && !(val % 1)) {
|
|
54148
|
+
addType = true;
|
|
54149
|
+
}
|
|
54150
|
+
break;
|
|
54151
|
+
case "number":
|
|
54152
|
+
if (Number.isFinite(val)) {
|
|
54153
|
+
addType = true;
|
|
54154
|
+
}
|
|
54155
|
+
break;
|
|
54156
|
+
case "nonFinite":
|
|
54157
|
+
if (typeof val === "number" && !Number.isFinite(val)) {
|
|
54158
|
+
addType = true;
|
|
54159
|
+
}
|
|
54160
|
+
break;
|
|
54161
|
+
case "object":
|
|
54162
|
+
if (val && typeof val === valueType) {
|
|
54163
|
+
addType = true;
|
|
54164
|
+
}
|
|
54165
|
+
break;
|
|
54166
|
+
case "array":
|
|
54167
|
+
if (Array.isArray(val)) {
|
|
54168
|
+
addType = true;
|
|
54169
|
+
}
|
|
54170
|
+
break;
|
|
54171
|
+
case "other":
|
|
54172
|
+
addType = this.currOtherTypeCallback(val, path2, parent2, parentPropName);
|
|
54173
|
+
break;
|
|
54174
|
+
case "null":
|
|
54175
|
+
if (val === null) {
|
|
54176
|
+
addType = true;
|
|
54177
|
+
}
|
|
54178
|
+
break;
|
|
54179
|
+
/* c8 ignore next 2 */
|
|
54180
|
+
default:
|
|
54181
|
+
throw new TypeError("Unknown value type " + valueType);
|
|
54182
|
+
}
|
|
54183
|
+
if (addType) {
|
|
54184
|
+
retObj = {
|
|
54185
|
+
path: path2,
|
|
54186
|
+
value: val,
|
|
54187
|
+
parent: parent2,
|
|
54188
|
+
parentProperty: parentPropName
|
|
54189
|
+
};
|
|
54190
|
+
this._handleCallback(retObj, callback, "value");
|
|
54191
|
+
return retObj;
|
|
54192
|
+
}
|
|
54193
|
+
} else if (loc[0] === "`" && val && Object.hasOwn(val, loc.slice(1))) {
|
|
54194
|
+
const locProp = loc.slice(1);
|
|
54195
|
+
addRet(this._trace(x2, val[locProp], push(path2, locProp), val, locProp, callback, hasArrExpr, true));
|
|
54196
|
+
} else if (loc.includes(",")) {
|
|
54197
|
+
const parts = loc.split(",");
|
|
54198
|
+
for (const part of parts) {
|
|
54199
|
+
addRet(this._trace(unshift(part, x2), val, path2, parent2, parentPropName, callback, true));
|
|
54200
|
+
}
|
|
54201
|
+
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
|
|
54202
|
+
addRet(this._trace(x2, val[loc], push(path2, loc), val, loc, callback, hasArrExpr, true));
|
|
54203
|
+
}
|
|
54204
|
+
if (this._hasParentSelector) {
|
|
54205
|
+
for (let t = 0; t < ret.length; t++) {
|
|
54206
|
+
const rett = ret[t];
|
|
54207
|
+
if (rett && rett.isParentSelector) {
|
|
54208
|
+
const tmp = this._trace(rett.expr, val, rett.path, parent2, parentPropName, callback, hasArrExpr);
|
|
54209
|
+
if (Array.isArray(tmp)) {
|
|
54210
|
+
ret[t] = tmp[0];
|
|
54211
|
+
const tl = tmp.length;
|
|
54212
|
+
for (let tt2 = 1; tt2 < tl; tt2++) {
|
|
54213
|
+
t++;
|
|
54214
|
+
ret.splice(t, 0, tmp[tt2]);
|
|
54215
|
+
}
|
|
54216
|
+
} else {
|
|
54217
|
+
ret[t] = tmp;
|
|
54218
|
+
}
|
|
54219
|
+
}
|
|
54220
|
+
}
|
|
54221
|
+
}
|
|
54222
|
+
return ret;
|
|
54223
|
+
};
|
|
54224
|
+
JSONPath.prototype._walk = function(val, f) {
|
|
54225
|
+
if (Array.isArray(val)) {
|
|
54226
|
+
const n = val.length;
|
|
54227
|
+
for (let i = 0; i < n; i++) {
|
|
54228
|
+
f(i);
|
|
54229
|
+
}
|
|
54230
|
+
} else if (val && typeof val === "object") {
|
|
54231
|
+
Object.keys(val).forEach((m) => {
|
|
54232
|
+
f(m);
|
|
54233
|
+
});
|
|
54234
|
+
}
|
|
54235
|
+
};
|
|
54236
|
+
JSONPath.prototype._slice = function(loc, expr, val, path2, parent2, parentPropName, callback) {
|
|
54237
|
+
if (!Array.isArray(val)) {
|
|
54238
|
+
return void 0;
|
|
54239
|
+
}
|
|
54240
|
+
const len = val.length, parts = loc.split(":"), step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
54241
|
+
let start = parts[0] && Number.parseInt(parts[0]) || 0, end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
54242
|
+
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
54243
|
+
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
54244
|
+
const ret = [];
|
|
54245
|
+
for (let i = start; i < end; i += step) {
|
|
54246
|
+
const tmp = this._trace(unshift(i, expr), val, path2, parent2, parentPropName, callback, true);
|
|
54247
|
+
tmp.forEach((t) => {
|
|
54248
|
+
ret.push(t);
|
|
54249
|
+
});
|
|
54250
|
+
}
|
|
54251
|
+
return ret;
|
|
54252
|
+
};
|
|
54253
|
+
JSONPath.prototype._eval = function(code, _v, _vname, path2, parent2, parentPropName) {
|
|
54254
|
+
this.currSandbox._$_parentProperty = parentPropName;
|
|
54255
|
+
this.currSandbox._$_parent = parent2;
|
|
54256
|
+
this.currSandbox._$_property = _vname;
|
|
54257
|
+
this.currSandbox._$_root = this.json;
|
|
54258
|
+
this.currSandbox._$_v = _v;
|
|
54259
|
+
const containsPath = code.includes("@path");
|
|
54260
|
+
if (containsPath) {
|
|
54261
|
+
this.currSandbox._$_path = JSONPath.toPathString(path2.concat([_vname]));
|
|
54262
|
+
}
|
|
54263
|
+
const scriptCacheKey = this.currEval + "Script:" + code;
|
|
54264
|
+
if (!JSONPath.cache[scriptCacheKey]) {
|
|
54265
|
+
let script = code.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
54266
|
+
if (containsPath) {
|
|
54267
|
+
script = script.replaceAll("@path", "_$_path");
|
|
54268
|
+
}
|
|
54269
|
+
if (this.currEval === "safe" || this.currEval === true || this.currEval === void 0) {
|
|
54270
|
+
JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);
|
|
54271
|
+
} else if (this.currEval === "native") {
|
|
54272
|
+
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
54273
|
+
} else if (typeof this.currEval === "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
54274
|
+
const CurrEval = this.currEval;
|
|
54275
|
+
JSONPath.cache[scriptCacheKey] = new CurrEval(script);
|
|
54276
|
+
} else if (typeof this.currEval === "function") {
|
|
54277
|
+
JSONPath.cache[scriptCacheKey] = {
|
|
54278
|
+
runInNewContext: (context) => this.currEval(script, context)
|
|
54279
|
+
};
|
|
54280
|
+
} else {
|
|
54281
|
+
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
54282
|
+
}
|
|
54283
|
+
}
|
|
54284
|
+
try {
|
|
54285
|
+
return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
|
|
54286
|
+
} catch (e) {
|
|
54287
|
+
if (this.ignoreEvalErrors) {
|
|
54288
|
+
return false;
|
|
54289
|
+
}
|
|
54290
|
+
throw new Error("jsonPath: " + e.message + ": " + code);
|
|
54291
|
+
}
|
|
54292
|
+
};
|
|
54293
|
+
JSONPath.cache = {};
|
|
54294
|
+
JSONPath.toPathString = function(pathArr) {
|
|
54295
|
+
const x2 = pathArr, n = x2.length;
|
|
54296
|
+
let p = "$";
|
|
54297
|
+
for (let i = 1; i < n; i++) {
|
|
54298
|
+
if (!/^(~|\^|@.*?\(\))$/u.test(x2[i])) {
|
|
54299
|
+
p += /^[0-9*]+$/u.test(x2[i]) ? "[" + x2[i] + "]" : "['" + x2[i] + "']";
|
|
54300
|
+
}
|
|
54301
|
+
}
|
|
54302
|
+
return p;
|
|
54303
|
+
};
|
|
54304
|
+
JSONPath.toPointer = function(pointer) {
|
|
54305
|
+
const x2 = pointer, n = x2.length;
|
|
54306
|
+
let p = "";
|
|
54307
|
+
for (let i = 1; i < n; i++) {
|
|
54308
|
+
if (!/^(~|\^|@.*?\(\))$/u.test(x2[i])) {
|
|
54309
|
+
p += "/" + x2[i].toString().replaceAll("~", "~0").replaceAll("/", "~1");
|
|
54310
|
+
}
|
|
54311
|
+
}
|
|
54312
|
+
return p;
|
|
54313
|
+
};
|
|
54314
|
+
JSONPath.toPathArray = function(expr) {
|
|
54315
|
+
const {
|
|
54316
|
+
cache
|
|
54317
|
+
} = JSONPath;
|
|
54318
|
+
if (cache[expr]) {
|
|
54319
|
+
return cache[expr].concat();
|
|
54320
|
+
}
|
|
54321
|
+
const subx = [];
|
|
54322
|
+
const normalized = expr.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function($0, $1) {
|
|
54323
|
+
return "[#" + (subx.push($1) - 1) + "]";
|
|
54324
|
+
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function($0, prop) {
|
|
54325
|
+
return "['" + prop.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
54326
|
+
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function($0, ups) {
|
|
54327
|
+
return ";" + ups.split("").join(";") + ";";
|
|
54328
|
+
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "");
|
|
54329
|
+
const exprList = normalized.split(";").map(function(exp) {
|
|
54330
|
+
const match = exp.match(/#(\d+)/u);
|
|
54331
|
+
return !match || !match[1] ? exp : subx[match[1]];
|
|
54332
|
+
});
|
|
54333
|
+
cache[expr] = exprList;
|
|
54334
|
+
return cache[expr].concat();
|
|
54335
|
+
};
|
|
54336
|
+
JSONPath.prototype.safeVm = {
|
|
54337
|
+
Script: SafeScript
|
|
54338
|
+
};
|
|
54339
|
+
const moveToAnotherArray = function(source, target, conditionCb) {
|
|
54340
|
+
const il = source.length;
|
|
54341
|
+
for (let i = 0; i < il; i++) {
|
|
54342
|
+
const item = source[i];
|
|
54343
|
+
if (conditionCb(item)) {
|
|
54344
|
+
target.push(source.splice(i--, 1)[0]);
|
|
54345
|
+
}
|
|
54346
|
+
}
|
|
54347
|
+
};
|
|
54348
|
+
class Script {
|
|
54349
|
+
/**
|
|
54350
|
+
* @param {string} expr Expression to evaluate
|
|
54351
|
+
*/
|
|
54352
|
+
constructor(expr) {
|
|
54353
|
+
this.code = expr;
|
|
54354
|
+
}
|
|
54355
|
+
/**
|
|
54356
|
+
* @param {object} context Object whose items will be added
|
|
54357
|
+
* to evaluation
|
|
54358
|
+
* @returns {EvaluatedResult} Result of evaluated code
|
|
54359
|
+
*/
|
|
54360
|
+
runInNewContext(context) {
|
|
54361
|
+
let expr = this.code;
|
|
54362
|
+
const keys2 = Object.keys(context);
|
|
54363
|
+
const funcs = [];
|
|
54364
|
+
moveToAnotherArray(keys2, funcs, (key) => {
|
|
54365
|
+
return typeof context[key] === "function";
|
|
54366
|
+
});
|
|
54367
|
+
const values = keys2.map((vr) => {
|
|
54368
|
+
return context[vr];
|
|
54369
|
+
});
|
|
54370
|
+
const funcString = funcs.reduce((s, func) => {
|
|
54371
|
+
let fString = context[func].toString();
|
|
54372
|
+
if (!/function/u.test(fString)) {
|
|
54373
|
+
fString = "function " + fString;
|
|
54374
|
+
}
|
|
54375
|
+
return "var " + func + "=" + fString + ";" + s;
|
|
54376
|
+
}, "");
|
|
54377
|
+
expr = funcString + expr;
|
|
54378
|
+
if (!/(['"])use strict\1/u.test(expr) && !keys2.includes("arguments")) {
|
|
54379
|
+
expr = "var arguments = undefined;" + expr;
|
|
54380
|
+
}
|
|
54381
|
+
expr = expr.replace(/;\s*$/u, "");
|
|
54382
|
+
const lastStatementEnd = expr.lastIndexOf(";");
|
|
54383
|
+
const code = lastStatementEnd !== -1 ? expr.slice(0, lastStatementEnd + 1) + " return " + expr.slice(lastStatementEnd + 1) : " return " + expr;
|
|
54384
|
+
return new Function(...keys2, code)(...values);
|
|
54385
|
+
}
|
|
54386
|
+
}
|
|
54387
|
+
JSONPath.prototype.vm = {
|
|
54388
|
+
Script
|
|
54389
|
+
};
|
|
52448
54390
|
const parseJsonSchema = (schema2, paramsConfig = /* @__PURE__ */ new Map()) => {
|
|
52449
54391
|
if (!schema2 || typeof schema2 !== "object") return schema2;
|
|
52450
54392
|
switch (schema2.type) {
|
|
@@ -52466,7 +54408,7 @@ const parseJsonSchema = (schema2, paramsConfig = /* @__PURE__ */ new Map()) => {
|
|
|
52466
54408
|
};
|
|
52467
54409
|
function processJsonSchemaSubModel0(mapItem, apiData) {
|
|
52468
54410
|
return mapItem.fields.reduce((acc, { leftFieldKey, rightFieldKey }) => {
|
|
52469
|
-
let value =
|
|
54411
|
+
let value = JSONPath({ path: rightFieldKey, json: apiData })?.[0];
|
|
52470
54412
|
value = (Array.isArray(value) ? value[0] : value) ?? void 0;
|
|
52471
54413
|
acc[leftFieldKey] = typeof value === "object" ? void 0 : value;
|
|
52472
54414
|
return acc;
|
|
@@ -52474,7 +54416,7 @@ function processJsonSchemaSubModel0(mapItem, apiData) {
|
|
|
52474
54416
|
}
|
|
52475
54417
|
function processJsonSchemaSubModel1(mapItem, apiData) {
|
|
52476
54418
|
const fieldValues = mapItem.fields.reduce((acc, { leftFieldKey, rightFieldKey }) => {
|
|
52477
|
-
let value =
|
|
54419
|
+
let value = JSONPath({ path: rightFieldKey, json: apiData });
|
|
52478
54420
|
let arr = Array.isArray(value) ? value.filter((v) => v != null && typeof v !== "object") : value != null && typeof value !== "object" ? [value] : [];
|
|
52479
54421
|
acc[leftFieldKey] = arr;
|
|
52480
54422
|
return acc;
|
|
@@ -98183,8 +100125,18 @@ async function resolveCheckTableItemInfos(ctx) {
|
|
|
98183
100125
|
protocolKey: checkTableDs.joinModelKey,
|
|
98184
100126
|
instId: ctx.instanceId
|
|
98185
100127
|
});
|
|
100128
|
+
res.data?.forEach((item) => {
|
|
100129
|
+
delete item.id_;
|
|
100130
|
+
});
|
|
98186
100131
|
return res;
|
|
98187
100132
|
}
|
|
100133
|
+
async function waitForDataManagerSettle() {
|
|
100134
|
+
await nextTick();
|
|
100135
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
100136
|
+
}
|
|
100137
|
+
function syncInitRawDataSnapshot(doc) {
|
|
100138
|
+
doc.docRuntimeMeta.handleInfo.initRawDataSnapshot = cloneDeep(doc.dataManager.getRawData());
|
|
100139
|
+
}
|
|
98188
100140
|
function snapshotDocInfo(docInst) {
|
|
98189
100141
|
return {
|
|
98190
100142
|
pages: docInst?.pages ?? [],
|
|
@@ -98198,6 +100150,7 @@ async function initializeDocumentEngine(props, payload, result) {
|
|
|
98198
100150
|
const { id, requestInfo, fillModeType, paramsConfig } = result;
|
|
98199
100151
|
const mainModelKey = requestInfo.modelKey || payload.modelKey || "";
|
|
98200
100152
|
const materialNo = paramsConfig?.materialNo || requestInfo.materialNo;
|
|
100153
|
+
await payload.ctx.runtime.ensureModelFieldsReady(mainModelKey);
|
|
98201
100154
|
await addSubModelsToFieldScope(mainModelKey, payload.ctx);
|
|
98202
100155
|
const masterSlaveList = payload.ctx.runtime.getMasterSlaveFieldList(mainModelKey);
|
|
98203
100156
|
const cloneRuntimeJson = cloneDeep(JSON.parse(requestInfo.runtimeJson || "{}"));
|
|
@@ -98252,7 +100205,7 @@ async function initializeDocumentEngine(props, payload, result) {
|
|
|
98252
100205
|
const rawData = conversionFormState({
|
|
98253
100206
|
masterSlaveList,
|
|
98254
100207
|
interfaceData,
|
|
98255
|
-
|
|
100208
|
+
subTableInfoList: docModel.getSubTableInfoList() ?? []
|
|
98256
100209
|
});
|
|
98257
100210
|
const docRuntimeMeta = {
|
|
98258
100211
|
...requestInfo,
|
|
@@ -98279,7 +100232,8 @@ async function initializeDocumentEngine(props, payload, result) {
|
|
|
98279
100232
|
});
|
|
98280
100233
|
doc.dataManager.setRawData(rawData, defaultDataMap);
|
|
98281
100234
|
doc.dataManager.applyInitData({ ...paramMap, ...dsMap });
|
|
98282
|
-
|
|
100235
|
+
await waitForDataManagerSettle();
|
|
100236
|
+
syncInitRawDataSnapshot(doc);
|
|
98283
100237
|
const docInfo = snapshotDocInfo(doc);
|
|
98284
100238
|
return {
|
|
98285
100239
|
doc,
|
|
@@ -98290,7 +100244,8 @@ async function finalizeDesignModelImport(doc, docModel) {
|
|
|
98290
100244
|
doc.setModel(docModel);
|
|
98291
100245
|
const mainModelKey = doc.mainModelKey;
|
|
98292
100246
|
doc.dataManager.setRawData({}, {});
|
|
98293
|
-
|
|
100247
|
+
await waitForDataManagerSettle();
|
|
100248
|
+
syncInitRawDataSnapshot(doc);
|
|
98294
100249
|
doc.commandManager.undoStack.length = 0;
|
|
98295
100250
|
doc.commandManager.redoStack.length = 0;
|
|
98296
100251
|
doc.eventManager.cursorController.clearCursor();
|
|
@@ -98353,6 +100308,7 @@ function useDocumentFactory(props, payload) {
|
|
|
98353
100308
|
watch(
|
|
98354
100309
|
() => finisher.value,
|
|
98355
100310
|
() => {
|
|
100311
|
+
if (!docIns.value) return;
|
|
98356
100312
|
console.log("Document request success");
|
|
98357
100313
|
payload.onDocumentLoadSuccess?.();
|
|
98358
100314
|
}
|
|
@@ -98388,6 +100344,7 @@ function useDocumentFactory(props, payload) {
|
|
|
98388
100344
|
} = freshExecute;
|
|
98389
100345
|
const mainModelKey = requestInfo.modelKey || payload.modelKey || "";
|
|
98390
100346
|
const materialNo = paramsConfig?.materialNo || props.materialNo;
|
|
100347
|
+
await payload.ctx.runtime.ensureModelFieldsReady(mainModelKey);
|
|
98391
100348
|
const masterSlaveList = payload.ctx.runtime.getMasterSlaveFieldList(mainModelKey);
|
|
98392
100349
|
const instances = doc.model?.getWidgetInstances() ?? [];
|
|
98393
100350
|
const { initDocModelJson } = doc.docRuntimeMeta.handleInfo;
|
|
@@ -98416,13 +100373,13 @@ function useDocumentFactory(props, payload) {
|
|
|
98416
100373
|
const rawData = conversionFormState({
|
|
98417
100374
|
masterSlaveList,
|
|
98418
100375
|
interfaceData,
|
|
98419
|
-
|
|
100376
|
+
subTableInfoList: doc.model?.getSubTableInfoList() ?? []
|
|
98420
100377
|
});
|
|
98421
100378
|
doc.dataManager.setRawData(rawData);
|
|
98422
|
-
await
|
|
98423
|
-
|
|
100379
|
+
await waitForDataManagerSettle();
|
|
100380
|
+
syncInitRawDataSnapshot(doc);
|
|
98424
100381
|
} finally {
|
|
98425
|
-
await
|
|
100382
|
+
await waitForDataManagerSettle();
|
|
98426
100383
|
isRefreshingData.value = false;
|
|
98427
100384
|
doc.eventManager.cursorController.clearCursor();
|
|
98428
100385
|
}
|
|
@@ -98888,6 +100845,13 @@ class SuiteRuntime {
|
|
|
98888
100845
|
getModel(modelKey) {
|
|
98889
100846
|
return this.modelService.getModelSync(modelKey);
|
|
98890
100847
|
}
|
|
100848
|
+
/**
|
|
100849
|
+
* 确保主模型字段已拉取并写入缓存(避免 preload 与文档 immediate 加载竞态)。
|
|
100850
|
+
*/
|
|
100851
|
+
async ensureModelFieldsReady(modelKey) {
|
|
100852
|
+
if (!modelKey) return;
|
|
100853
|
+
await this.loadFieldList(modelKey);
|
|
100854
|
+
}
|
|
98891
100855
|
getMasterSlaveFieldList(modelKey) {
|
|
98892
100856
|
return this.fieldService.getFieldList(modelKey)?.filter((i) => i.type === FIELD_TYPE.MASTERSLAVE) || [];
|
|
98893
100857
|
}
|
|
@@ -103364,7 +105328,8 @@ const _sfc_main$2y = /* @__PURE__ */ defineComponent({
|
|
|
103364
105328
|
};
|
|
103365
105329
|
const copyRow = () => {
|
|
103366
105330
|
const { path: path2, index: index2 } = getCtx();
|
|
103367
|
-
const
|
|
105331
|
+
const storageIndex = props.doc.dataManager.resolveSubtableVisibleIndex(path2, index2);
|
|
105332
|
+
const data = props.doc.dataManager.get(`${path2}[${storageIndex}]`) || {};
|
|
103368
105333
|
props.doc.dataManager.insertAt(path2, index2 + 1, data);
|
|
103369
105334
|
};
|
|
103370
105335
|
const actionHandlers = {
|
|
@@ -103506,7 +105471,7 @@ const _sfc_main$2y = /* @__PURE__ */ defineComponent({
|
|
|
103506
105471
|
};
|
|
103507
105472
|
}
|
|
103508
105473
|
});
|
|
103509
|
-
const SubTableAction = /* @__PURE__ */ _export_sfc(_sfc_main$2y, [["__scopeId", "data-v-
|
|
105474
|
+
const SubTableAction = /* @__PURE__ */ _export_sfc(_sfc_main$2y, [["__scopeId", "data-v-da25771b"]]);
|
|
103510
105475
|
const _sfc_main$2x = /* @__PURE__ */ defineComponent({
|
|
103511
105476
|
__name: "index",
|
|
103512
105477
|
props: {
|
|
@@ -103889,9 +105854,6 @@ function rowKey(row, fallbackIndex) {
|
|
|
103889
105854
|
}
|
|
103890
105855
|
return `idx:${fallbackIndex}`;
|
|
103891
105856
|
}
|
|
103892
|
-
function normalizeFormData(data) {
|
|
103893
|
-
return getSubmitFormData(data || {});
|
|
103894
|
-
}
|
|
103895
105857
|
function getFieldMeta(metaMap, runtimePath) {
|
|
103896
105858
|
if (!metaMap) return {};
|
|
103897
105859
|
return metaMap.get(runtimePath) || {};
|
|
@@ -103991,8 +105953,8 @@ function buildWidgetFieldMetaMap(instances) {
|
|
|
103991
105953
|
return map;
|
|
103992
105954
|
}
|
|
103993
105955
|
function buildFieldChangeList(params) {
|
|
103994
|
-
const baseline =
|
|
103995
|
-
const current =
|
|
105956
|
+
const baseline = getSubmitFormData(params.baselineData || {}, params.subTableInfoList);
|
|
105957
|
+
const current = getSubmitFormData(params.currentData || {}, params.subTableInfoList);
|
|
103996
105958
|
const changeList = [];
|
|
103997
105959
|
const keys2 = /* @__PURE__ */ new Set([...Object.keys(baseline || {}), ...Object.keys(current || {})]);
|
|
103998
105960
|
for (const fieldKey of keys2) {
|
|
@@ -104091,8 +106053,9 @@ function useDocOperations(docRef) {
|
|
|
104091
106053
|
const baselineSnapshot = doc.dataManager.getRawData();
|
|
104092
106054
|
const instances = doc.getWidgetInstances() ?? [];
|
|
104093
106055
|
const widgetMetaMap = buildWidgetFieldMetaMap(instances);
|
|
106056
|
+
const subTableInfoList = doc.model?.getSubTableInfoList() ?? [];
|
|
104094
106057
|
doc.setMode(DocModeTypeConst.Fill);
|
|
104095
|
-
return { baselineSnapshot, widgetMetaMap };
|
|
106058
|
+
return { baselineSnapshot, widgetMetaMap, subTableInfoList };
|
|
104096
106059
|
}
|
|
104097
106060
|
async function computeBaselineChanges(ctx) {
|
|
104098
106061
|
await Promise.resolve();
|
|
@@ -104104,7 +106067,8 @@ function useDocOperations(docRef) {
|
|
|
104104
106067
|
return buildFieldChangeList({
|
|
104105
106068
|
baselineData: ctx.baselineSnapshot,
|
|
104106
106069
|
currentData,
|
|
104107
|
-
widgetMetaMap: ctx.widgetMetaMap
|
|
106070
|
+
widgetMetaMap: ctx.widgetMetaMap,
|
|
106071
|
+
subTableInfoList: ctx.subTableInfoList
|
|
104108
106072
|
});
|
|
104109
106073
|
}
|
|
104110
106074
|
function setAnnotation(ids, list) {
|
|
@@ -104203,6 +106167,13 @@ function useDocController(factory2, ops) {
|
|
|
104203
106167
|
rawData() {
|
|
104204
106168
|
return doc.dataManager.getRawData();
|
|
104205
106169
|
},
|
|
106170
|
+
getSubmitFormData(formData) {
|
|
106171
|
+
const subTableInfoList = doc.model?.getSubTableInfoList() ?? [];
|
|
106172
|
+
return getSubmitFormData(
|
|
106173
|
+
formData ?? doc.dataManager.getRawData(),
|
|
106174
|
+
subTableInfoList
|
|
106175
|
+
);
|
|
106176
|
+
},
|
|
104206
106177
|
setRawData(data, defaultDataMap) {
|
|
104207
106178
|
doc.dataManager.setRawData(data, defaultDataMap);
|
|
104208
106179
|
},
|
|
@@ -104308,9 +106279,14 @@ function useDocLooperAutoSaveNotify(factory2, ops, options) {
|
|
|
104308
106279
|
}
|
|
104309
106280
|
function releaseSuppressOnLoad() {
|
|
104310
106281
|
cancelFlushNotify();
|
|
104311
|
-
|
|
106282
|
+
void (async () => {
|
|
106283
|
+
await waitForDataManagerSettle();
|
|
106284
|
+
const doc = factory2.docIns.value;
|
|
106285
|
+
if (doc) {
|
|
106286
|
+
syncInitRawDataSnapshot(doc);
|
|
106287
|
+
}
|
|
104312
106288
|
suppress = false;
|
|
104313
|
-
});
|
|
106289
|
+
})();
|
|
104314
106290
|
}
|
|
104315
106291
|
if (options.suppressSignal) {
|
|
104316
106292
|
watch(
|
|
@@ -111134,10 +113110,10 @@ const _sfc_main$1X = /* @__PURE__ */ defineComponent({
|
|
|
111134
113110
|
get() {
|
|
111135
113111
|
if (docInst.value.isInEditMode()) {
|
|
111136
113112
|
const value2 = docInst.value?.dataManager?.getDefault(runtimeValuePath.value);
|
|
111137
|
-
return getValue$1(value2, isMultiple.value);
|
|
113113
|
+
return toBoolean(getValue$1(value2, isMultiple.value));
|
|
111138
113114
|
}
|
|
111139
113115
|
const value = docInst.value?.dataManager?.get(runtimeValuePath.value);
|
|
111140
|
-
return getValue$1(value, isMultiple.value);
|
|
113116
|
+
return toBoolean(getValue$1(value, isMultiple.value));
|
|
111141
113117
|
},
|
|
111142
113118
|
set(v) {
|
|
111143
113119
|
const data = setValue(v, runtimeValuePath.value, {
|
|
@@ -122331,8 +124307,8 @@ const edhrSuitePlugin = {
|
|
|
122331
124307
|
key: SUITE_KEY,
|
|
122332
124308
|
install: installEdhrSuite
|
|
122333
124309
|
};
|
|
122334
|
-
function registerSuite(
|
|
122335
|
-
|
|
124310
|
+
function registerSuite(plugin2) {
|
|
124311
|
+
plugin2.install();
|
|
122336
124312
|
}
|
|
122337
124313
|
const _hoisted_1$e = { class: "options-dropdown" };
|
|
122338
124314
|
const _hoisted_2$9 = { class: "options-search" };
|
|
@@ -124852,7 +126828,6 @@ export {
|
|
|
124852
126828
|
GctLayout,
|
|
124853
126829
|
PageSizeEnumConst,
|
|
124854
126830
|
edhrSuitePlugin,
|
|
124855
|
-
getSubmitFormData,
|
|
124856
126831
|
registerSuite,
|
|
124857
126832
|
setupPlatformAdapters,
|
|
124858
126833
|
setupVueRuntime,
|