@rugal.tu/vuemodel3 1.3.8 → 1.4.1

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.
@@ -1187,7 +1187,12 @@
1187
1187
  exports.VueStore = VueStore;
1188
1188
  class VueCommand extends VueStore {
1189
1189
  $IsInited = false;
1190
+ $CommandMap;
1190
1191
  $QueryDomName = null;
1192
+ constructor() {
1193
+ super();
1194
+ this.$SetupCommandMap();
1195
+ }
1191
1196
  WithQueryDomName(QueryDomName) {
1192
1197
  this.$QueryDomName = QueryDomName;
1193
1198
  exports.Queryer.WithDomName(this.$QueryDomName);
@@ -1213,9 +1218,10 @@
1213
1218
  this.$AddCommand(DomName, 'v-model', SetOption);
1214
1219
  return this;
1215
1220
  }
1216
- AddV_Slot(DomName, SlotKey, StorePath) {
1217
- let SetOption = this.$ConvertCommandOption(StorePath);
1218
- SetOption.CommandKey = SlotKey;
1221
+ AddV_Slot(DomName, SlotKey, Option) {
1222
+ let SetOption = this.$ConvertCommandOption(DomName, Option);
1223
+ if (SlotKey != null)
1224
+ SetOption.CommandKey = SlotKey;
1219
1225
  this.$AddCommand(DomName, `v-slot`, SetOption);
1220
1226
  return this;
1221
1227
  }
@@ -1354,77 +1360,8 @@
1354
1360
  RootNode = TreeRoot;
1355
1361
  let RootPaths = UsingRootNode ? [] : this.Paths(TreeRoot);
1356
1362
  this.$ParseTreeSet(RootPaths, TreeSet, AllSetInfo);
1357
- let CommandMap = {
1358
- 'v-text': (Info, Option) => {
1359
- Model.AddV_Text(Option.TargetDom, Option.TargetValue);
1360
- },
1361
- 'v-model': (Info, Option) => {
1362
- if (typeof (Info.StoreValue) == 'function') {
1363
- Model.$Error(`v-model command value must be a string or string[], path: ${this.ToJoin(Info.DomPaths)}`);
1364
- return;
1365
- }
1366
- Model.AddV_Model(Option.TargetDom, Option.TargetPath, {
1367
- ModelValue: Info.CommandKey,
1368
- });
1369
- },
1370
- 'v-for': (Info, Option) => {
1371
- Model.AddV_For(Option.TargetDom, Option.TargetValue, Info.CommandKey);
1372
- },
1373
- 'v-if': (Info, Option) => {
1374
- Model.AddV_If(Option.TargetDom, Option.TargetValue);
1375
- },
1376
- 'v-else-if': (Info, Option) => {
1377
- Model.AddV_ElseIf(Option.TargetDom, Option.TargetValue);
1378
- },
1379
- 'v-else': (Info, Option) => {
1380
- Model.AddV_Else(Option.TargetDom);
1381
- },
1382
- 'v-show': (Info, Option) => {
1383
- Model.AddV_Show(Option.TargetDom, Option.TargetValue);
1384
- },
1385
- 'v-bind': (Info, Option) => {
1386
- if (!Option.TargetValue)
1387
- return;
1388
- Model.AddV_Bind(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Params);
1389
- },
1390
- 'v-on': (Info, Option) => {
1391
- Model.AddV_On(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Params);
1392
- },
1393
- 'v-slot': (Info, Option) => {
1394
- if (Array.isArray(Info.StoreValue) || typeof (Info.StoreValue) == 'function') {
1395
- Model.$Error(`v-slot command value must be a string, path: ${this.ToJoin(Info.DomPaths)}`);
1396
- return;
1397
- }
1398
- Model.AddV_Slot(Option.TargetDom, Info.CommandKey, Option.TargetPath);
1399
- },
1400
- 'v-on-mounted': (Info, Option) => {
1401
- Model.AddV_OnMounted(Option.TargetDom, Option.TargetValue, Info.CommandKey);
1402
- },
1403
- 'v-on-unmounted': (Info, Option) => {
1404
- Model.AddV_OnUnMounted(Option.TargetDom, Option.TargetValue, Info.CommandKey);
1405
- },
1406
- 'watch': (Info, Option) => {
1407
- if (typeof (Info.StoreValue) != 'function') {
1408
- Model.$Error(`watch command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
1409
- return;
1410
- }
1411
- Model.AddV_Watch(Info.DomPaths, Info.StoreValue);
1412
- },
1413
- 'func': (Info, Option) => {
1414
- if (typeof (Info.StoreValue) != 'function') {
1415
- Model.$Error(`func command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
1416
- return;
1417
- }
1418
- Model.AddV_Function(['event', ...Info.DomPaths, Info.CommandKey], Info.StoreValue);
1419
- },
1420
- 'using': (Info, Option) => {
1421
- if (typeof (Info.StoreValue) === 'function') {
1422
- Info.StoreValue(Info.DomPaths, Info.Nodes);
1423
- }
1424
- }
1425
- };
1426
1363
  for (let Info of AllSetInfo) {
1427
- let ActionSet = CommandMap[Info.Command];
1364
+ let ActionSet = this.$CommandMap[Info.Command];
1428
1365
  if (ActionSet == null) {
1429
1366
  Model.$Error(`${Info.Command} command is not allowed, path: ${this.ToJoin(Info.DomPaths)}`);
1430
1367
  continue;
@@ -1448,15 +1385,38 @@
1448
1385
  let TargetDom = NeedQuery ? Info.Nodes : Info.DomPaths;
1449
1386
  let TargetPath = [];
1450
1387
  let TargetValue;
1451
- if (typeof (Info.StoreValue) != 'function') {
1452
- if (Option?.UseTreePath)
1453
- TargetPath = [...Info.TreePaths];
1454
- if (Option?.UseDomStore || Info.StoreValue == '.')
1455
- TargetPath.push(Info.DomName);
1456
- else if (Info.StoreValue != null && Info.StoreValue != '')
1457
- TargetPath = this.Paths(TargetPath, Info.StoreValue);
1388
+ if (typeof Info.StoreValue === 'function') {
1389
+ TargetValue = {
1390
+ Target: Info.StoreValue,
1391
+ FuncArgs: Info.Args,
1392
+ };
1393
+ }
1394
+ else {
1395
+ if (typeof Info.StoreValue === 'string' || Array.isArray(Info.StoreValue)) {
1396
+ Info.StoreValue = Model.ToJoin(Info.StoreValue);
1397
+ if (Option?.UseTreePath)
1398
+ TargetPath = [...Info.TreePaths];
1399
+ if (Option?.UseDomStore || Info.StoreValue == '.')
1400
+ TargetPath.push(Info.DomName);
1401
+ else if (Info.StoreValue != null && Info.StoreValue != '')
1402
+ TargetPath = this.Paths(TargetPath, Info.StoreValue);
1403
+ TargetValue = TargetPath.length > 0 ? TargetPath : Info.StoreValue;
1404
+ }
1405
+ else {
1406
+ let NewStoreValue = {
1407
+ Target: Info.StoreValue?.TargetFunc,
1408
+ FuncArgs: Info.StoreValue?.Args,
1409
+ };
1410
+ TargetValue = NewStoreValue;
1411
+ if (Info.StoreValue?.Args != null) {
1412
+ let Args = Model.ToJoin(Info.StoreValue.Args);
1413
+ if (Info.CommandKey == null || Info.CommandKey == '')
1414
+ Info.CommandKey = Args;
1415
+ else
1416
+ Info.CommandKey = Model.ToJoin([Info.CommandKey, Args], ', ');
1417
+ }
1418
+ }
1458
1419
  }
1459
- TargetValue = TargetPath.length > 0 ? TargetPath : Info.StoreValue;
1460
1420
  if (TargetValue == '')
1461
1421
  continue;
1462
1422
  ActionSet(Info, {
@@ -1468,76 +1428,153 @@
1468
1428
  return this;
1469
1429
  }
1470
1430
  $ParseTreeSet(Paths, TreeSet, Result) {
1431
+ const TreeNodeReges = /^:(?<next>.+)$/;
1471
1432
  let AllKeys = Object.keys(TreeSet);
1472
- let ParamRegex = /^(.+?)\(([^)]*)\)$/;
1473
1433
  for (let i = 0; i < AllKeys.length; i++) {
1474
1434
  let Command = AllKeys[i];
1475
1435
  let SetPair = TreeSet[Command];
1476
1436
  let DomPaths = [...Paths];
1477
1437
  let TreePaths = [...Paths];
1478
1438
  let DomName = TreePaths.pop();
1479
- if (!Command.includes(':')) {
1480
- let HasParams = Command.match(ParamRegex);
1481
- let CommandKey = null;
1482
- if (HasParams && HasParams.length >= 3) {
1483
- Command = HasParams[1];
1484
- CommandKey = HasParams[2];
1485
- }
1486
- Result.push({
1487
- Command: Command,
1488
- StoreValue: SetPair,
1489
- TreePaths: TreePaths,
1490
- DomPaths: DomPaths,
1491
- DomName: DomName,
1492
- CommandKey: CommandKey,
1493
- });
1494
- continue;
1495
- }
1496
- let Commands = Command.split(':');
1497
- if (Command.length < 2) {
1498
- Model.$Error(`command ${Command} invalid`);
1499
- continue;
1500
- }
1501
- Command = Commands.shift();
1502
- let Params = null;
1503
- if (Commands.length > 0) {
1504
- let LastCommand = Commands.pop();
1505
- let HasParams = LastCommand.match(ParamRegex);
1506
- if (HasParams && HasParams.length >= 3) {
1507
- Commands.push(HasParams[1]);
1508
- Params = HasParams[2];
1509
- }
1510
- else
1511
- Commands.push(LastCommand);
1512
- }
1513
- let NextDomName = Model.ToJoin(Commands, ':');
1514
- if (Command == '') {
1515
- if (typeof SetPair != 'function')
1516
- this.$ParseTreeSet([...Paths, NextDomName], SetPair, Result);
1517
- else {
1439
+ let TreeNodeResult = Command.match(TreeNodeReges);
1440
+ if (TreeNodeResult) {
1441
+ let NextDomName = TreeNodeResult.groups.next;
1442
+ if (typeof SetPair === 'function') {
1518
1443
  Result.push({
1519
1444
  Command: 'using',
1520
- CommandKey: null,
1521
1445
  StoreValue: SetPair,
1522
1446
  TreePaths: [...DomPaths],
1523
1447
  DomPaths: [...DomPaths, NextDomName],
1524
1448
  DomName: NextDomName,
1525
- Params: Params,
1526
1449
  });
1527
1450
  }
1451
+ else {
1452
+ this.$ParseTreeSet([...Paths, NextDomName], SetPair, Result);
1453
+ }
1528
1454
  continue;
1529
1455
  }
1456
+ let GetCommandPart = (FindCommand, StartChar, EndChar) => {
1457
+ if (!FindCommand.includes(StartChar) || !FindCommand.includes(EndChar))
1458
+ return null;
1459
+ let StartIndex = FindCommand.indexOf(StartChar);
1460
+ let EndIndex = FindCommand.lastIndexOf(EndChar);
1461
+ let Result = FindCommand.slice(StartIndex + 1, EndIndex).trim();
1462
+ return Result?.trim();
1463
+ };
1464
+ let GetCommandWithKey = (FindCommand) => {
1465
+ let ArgsStart = null;
1466
+ let ForKeyStart = null;
1467
+ if (FindCommand.includes('('))
1468
+ ArgsStart = FindCommand.indexOf('(');
1469
+ if (FindCommand.includes('<'))
1470
+ ForKeyStart = FindCommand.indexOf('<');
1471
+ let CommandWithKey = null;
1472
+ if (ArgsStart == null && ForKeyStart == null) {
1473
+ CommandWithKey = FindCommand;
1474
+ }
1475
+ else if (ArgsStart == null || ForKeyStart == null) {
1476
+ let MinIndex = ArgsStart ?? ForKeyStart;
1477
+ CommandWithKey = FindCommand.slice(0, MinIndex);
1478
+ }
1479
+ else {
1480
+ let MinIndex = Math.min(ArgsStart, ForKeyStart);
1481
+ CommandWithKey = FindCommand.slice(0, MinIndex);
1482
+ }
1483
+ let Command = CommandWithKey;
1484
+ let CommandKey = null;
1485
+ if (CommandWithKey.includes(':')) {
1486
+ let CommandKeyStart = Command.indexOf(':');
1487
+ Command = CommandWithKey.slice(0, CommandKeyStart);
1488
+ CommandKey = CommandWithKey.slice(CommandKeyStart + 1);
1489
+ }
1490
+ return {
1491
+ Command: Command?.trim(),
1492
+ CommandKey: CommandKey?.trim(),
1493
+ };
1494
+ };
1495
+ let Args = GetCommandPart(Command, '(', ')');
1496
+ let ForKey = GetCommandPart(Command, '<', '>');
1497
+ let CommandWithKey = GetCommandWithKey(Command);
1530
1498
  Result.push({
1531
- Command: Command,
1532
- CommandKey: NextDomName,
1499
+ Command: CommandWithKey?.Command,
1500
+ CommandKey: CommandWithKey?.CommandKey,
1501
+ ForKey: ForKey,
1502
+ Args: Args,
1533
1503
  StoreValue: SetPair,
1534
1504
  TreePaths: TreePaths,
1535
1505
  DomPaths: DomPaths,
1536
1506
  DomName: DomName,
1537
- Params: Params,
1538
1507
  });
1508
+ continue;
1539
1509
  }
1540
1510
  }
1511
+ $SetupCommandMap() {
1512
+ this.$CommandMap = {
1513
+ 'v-text': (Info, Option) => {
1514
+ Model.AddV_Text(Option.TargetDom, Option.TargetValue);
1515
+ },
1516
+ 'v-model': (Info, Option) => {
1517
+ if (typeof (Info.StoreValue) == 'function') {
1518
+ Model.$Error(`v-model command value must be a string or string[], path: ${this.ToJoin(Info.DomPaths)}`);
1519
+ return;
1520
+ }
1521
+ Model.AddV_Model(Option.TargetDom, Option.TargetPath, {
1522
+ ModelValue: Info.CommandKey,
1523
+ });
1524
+ },
1525
+ 'v-for': (Info, Option) => {
1526
+ Model.AddV_For(Option.TargetDom, Option.TargetValue, Info.ForKey);
1527
+ },
1528
+ 'v-if': (Info, Option) => {
1529
+ Model.AddV_If(Option.TargetDom, Option.TargetValue);
1530
+ },
1531
+ 'v-else-if': (Info, Option) => {
1532
+ Model.AddV_ElseIf(Option.TargetDom, Option.TargetValue);
1533
+ },
1534
+ 'v-else': (Info, Option) => {
1535
+ Model.AddV_Else(Option.TargetDom);
1536
+ },
1537
+ 'v-show': (Info, Option) => {
1538
+ Model.AddV_Show(Option.TargetDom, Option.TargetValue);
1539
+ },
1540
+ 'v-bind': (Info, Option) => {
1541
+ if (!Option.TargetValue)
1542
+ return;
1543
+ Model.AddV_Bind(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Args);
1544
+ },
1545
+ 'v-on': (Info, Option) => {
1546
+ Model.AddV_On(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Args);
1547
+ },
1548
+ 'v-slot': (Info, Option) => {
1549
+ Model.AddV_Slot(Option.TargetDom, Info.CommandKey, Option.TargetValue);
1550
+ },
1551
+ 'v-on-mounted': (Info, Option) => {
1552
+ Model.AddV_OnMounted(Option.TargetDom, Option.TargetValue, Info.Args);
1553
+ },
1554
+ 'v-on-unmounted': (Info, Option) => {
1555
+ Model.AddV_OnUnMounted(Option.TargetDom, Option.TargetValue, Info.Args);
1556
+ },
1557
+ 'watch': (Info, Option) => {
1558
+ if (typeof (Info.StoreValue) != 'function') {
1559
+ Model.$Error(`watch command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
1560
+ return;
1561
+ }
1562
+ Model.AddV_Watch(Info.DomPaths, Info.StoreValue);
1563
+ },
1564
+ 'func': (Info, Option) => {
1565
+ if (typeof (Info.StoreValue) != 'function') {
1566
+ Model.$Error(`func command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
1567
+ return;
1568
+ }
1569
+ Model.AddV_Function(['event', ...Info.DomPaths, Info.CommandKey], Info.StoreValue);
1570
+ },
1571
+ 'using': (Info, Option) => {
1572
+ if (typeof (Info.StoreValue) === 'function') {
1573
+ Info.StoreValue(Info.DomPaths, Info.Nodes);
1574
+ }
1575
+ }
1576
+ };
1577
+ }
1541
1578
  AddV_Property(PropertyPath, Option) {
1542
1579
  return this.AddV_PropertyFrom(this.Store, PropertyPath, Option);
1543
1580
  }
@@ -1645,11 +1682,7 @@
1645
1682
  Target = this.$GenerateEventFunction(FuncDomName, Target, Command);
1646
1683
  if (Option.FuncArgs) {
1647
1684
  let Args = this.ToJoin(Option.FuncArgs, ',');
1648
- if (!/^\(/.test(Args))
1649
- Args = `(${Args}`;
1650
- if (!/\)$/.test(Args))
1651
- Args += ')';
1652
- Target += Args;
1685
+ Target += `(${Args})`;
1653
1686
  }
1654
1687
  else if (Option.FuncAction) {
1655
1688
  Target += `()`;