@web-atoms/web-controls 2.3.98 → 2.3.100
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/auto-complete/AutoCompleteBox.js.map +1 -1
- package/dist/auto-complete/ItemHost.js.map +1 -1
- package/dist/basic/AtomChips.js.map +1 -1
- package/dist/basic/AtomRepeater.d.ts.map +1 -1
- package/dist/basic/AtomRepeater.js +6 -31
- package/dist/basic/AtomRepeater.js.map +1 -1
- package/dist/basic/AtomSuggestions.js.map +1 -1
- package/dist/basic/Calendar.js.map +1 -1
- package/dist/basic/DateField.js.map +1 -1
- package/dist/basic/DropDown.js.map +1 -1
- package/dist/basic/InlinePopup.js.map +1 -1
- package/dist/basic/ItemPath.d.ts +5 -0
- package/dist/basic/ItemPath.d.ts.map +1 -0
- package/dist/basic/ItemPath.js +79 -0
- package/dist/basic/ItemPath.js.map +1 -0
- package/dist/basic/MaskedInput.js.map +1 -1
- package/dist/basic/MaskedInputDiv.js.map +1 -1
- package/dist/basic/TableRepeater.js.map +1 -1
- package/dist/basic/TitleEditor.js.map +1 -1
- package/dist/calendar/AtomCalendar.js.map +1 -1
- package/dist/desktop-app/DesktopApp.js.map +1 -1
- package/dist/form/AtomField.js.map +1 -1
- package/dist/html-editor/commands/AddLink.js.map +1 -1
- package/dist/html-editor/commands/ChangeFont.js.map +1 -1
- package/dist/mobile/pages/AtomPageFrame.js.map +1 -1
- package/dist/mobile-app/MobileApp.js.map +1 -1
- package/dist/player/AtomVideoPlayer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/basic/AtomRepeater.tsx +3 -31
- package/src/basic/ItemPath.ts +87 -0
|
@@ -16,6 +16,7 @@ import ArrayLike from "../ArrayLike";
|
|
|
16
16
|
import InlinePopup from "./InlinePopup";
|
|
17
17
|
import InlinePopupControl from "./InlinePopupControl";
|
|
18
18
|
import MergeNode from "./MergeNode";
|
|
19
|
+
import ItemPath from "./ItemPath";
|
|
19
20
|
|
|
20
21
|
CSS(StyleRule()
|
|
21
22
|
.display("none")
|
|
@@ -1238,38 +1239,9 @@ export default class AtomRepeater<T = any> extends AtomControl {
|
|
|
1238
1239
|
let index = ~~itemIndex;
|
|
1239
1240
|
const item = this.items[index];
|
|
1240
1241
|
if (item) {
|
|
1241
|
-
if (itemPath) {
|
|
1242
|
+
if (itemPath ?? false) {
|
|
1242
1243
|
// check path...
|
|
1243
|
-
|
|
1244
|
-
if (/^[\{\"}]/.test(itemPath)) {
|
|
1245
|
-
this.dispatchItemEvent(clickEvent, item, recreate, e.target, JSON.parse(itemPath));
|
|
1246
|
-
return;
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
let nestedItem = {};
|
|
1250
|
-
const all: string[] = itemPath.split(",");
|
|
1251
|
-
for (const iterator of all) {
|
|
1252
|
-
let [name, paths] = iterator.split(/\=|\:/);
|
|
1253
|
-
if (paths === void 0) {
|
|
1254
|
-
if (all.length > 1) {
|
|
1255
|
-
throw new Error("Invalid path, please use name=path format");
|
|
1256
|
-
}
|
|
1257
|
-
paths = name;
|
|
1258
|
-
}
|
|
1259
|
-
let start = item;
|
|
1260
|
-
for (const path of paths.split(".")) {
|
|
1261
|
-
if (path === "$") {
|
|
1262
|
-
start = item;
|
|
1263
|
-
continue;
|
|
1264
|
-
}
|
|
1265
|
-
start = start[path];
|
|
1266
|
-
}
|
|
1267
|
-
if (all.length === 1) {
|
|
1268
|
-
nestedItem = start;
|
|
1269
|
-
break;
|
|
1270
|
-
}
|
|
1271
|
-
nestedItem[name] = start;
|
|
1272
|
-
}
|
|
1244
|
+
const nestedItem = ItemPath.get(item, itemPath.trim());
|
|
1273
1245
|
this.dispatchItemEvent(clickEvent, item, recreate, e.target, nestedItem);
|
|
1274
1246
|
return;
|
|
1275
1247
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const get = (start, path: string) => {
|
|
2
|
+
let item = start;
|
|
3
|
+
for (const iterator of path.split(".")) {
|
|
4
|
+
if (iterator === "$") {
|
|
5
|
+
item = start;
|
|
6
|
+
}
|
|
7
|
+
item = item[iterator];
|
|
8
|
+
}
|
|
9
|
+
return item;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function* getFragments(path: string) {
|
|
13
|
+
const regex = /([^\=\:]+)\s*[\=\:]\s*((('[^\\']*(((\\')|(''))[^\\']*)*')|("[^\\"]*(((\\")|(""))[^\\"]*)*"))|([^\,\;]+))\s*[\,\;]?\s*/gmi;
|
|
14
|
+
|
|
15
|
+
// Alternative syntax using RegExp constructor
|
|
16
|
+
// const regex = new RegExp('(([^\\=\\:]+)\\s*[\\=\\:]\\s*(([^\\,]+)|(\'[^\\\\\']*(((\\\\\')|(\'\'))[^\\\\\']*)*\')|("[^\\\\"]*(((\\\\")|(""))[^\\\\"]*)*")))[\\,\\;]?\\s*', 'gmi')
|
|
17
|
+
|
|
18
|
+
let m;
|
|
19
|
+
|
|
20
|
+
while ((m = regex.exec(path)) !== null) {
|
|
21
|
+
// This is necessary to avoid infinite loops with zero-width matches
|
|
22
|
+
if (m.index === regex.lastIndex) {
|
|
23
|
+
regex.lastIndex++;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
yield [m[1].trim(), m[2].trim()]
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default class ItemPath {
|
|
32
|
+
|
|
33
|
+
public static get(item, path: string) {
|
|
34
|
+
if (path.startsWith("$.")) {
|
|
35
|
+
return get(item, path);
|
|
36
|
+
}
|
|
37
|
+
if (/^[\{\"]/.test(path)) {
|
|
38
|
+
// it is a valid json..
|
|
39
|
+
const json = JSON.parse(path);
|
|
40
|
+
|
|
41
|
+
// should we have some sort of json embedding??
|
|
42
|
+
|
|
43
|
+
return json;
|
|
44
|
+
}
|
|
45
|
+
const target = {};
|
|
46
|
+
this.build(item, path, target);
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static build(item, path: string, target: any) {
|
|
51
|
+
for (let [key, value] of getFragments(path)) {
|
|
52
|
+
if (value.startsWith("$")) {
|
|
53
|
+
value = get(item, value);
|
|
54
|
+
target[key] = value;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (value.startsWith('"')) {
|
|
58
|
+
value = JSON.parse(value);
|
|
59
|
+
target[key] = value;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (value.startsWith("'")) {
|
|
63
|
+
value = value.substring(1, value.length - 1);
|
|
64
|
+
value = value.replace(/((\'\')|(\\\'))/, "'");
|
|
65
|
+
target[key] = value;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// these values are purposely compared
|
|
70
|
+
// at end because they will be used rarly
|
|
71
|
+
if (value === "true") {
|
|
72
|
+
target[key] = true;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (value === "false") {
|
|
76
|
+
target[key] = false;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (value === "null") {
|
|
80
|
+
target[key] = null;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
target[key] = Number(value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|