@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.
@@ -1169,7 +1169,12 @@ export class VueStore extends ApiStore {
1169
1169
  }
1170
1170
  export class VueCommand extends VueStore {
1171
1171
  $IsInited = false;
1172
+ $CommandMap;
1172
1173
  $QueryDomName = null;
1174
+ constructor() {
1175
+ super();
1176
+ this.$SetupCommandMap();
1177
+ }
1173
1178
  WithQueryDomName(QueryDomName) {
1174
1179
  this.$QueryDomName = QueryDomName;
1175
1180
  Queryer.WithDomName(this.$QueryDomName);
@@ -1195,9 +1200,10 @@ export class VueCommand extends VueStore {
1195
1200
  this.$AddCommand(DomName, 'v-model', SetOption);
1196
1201
  return this;
1197
1202
  }
1198
- AddV_Slot(DomName, SlotKey, StorePath) {
1199
- let SetOption = this.$ConvertCommandOption(StorePath);
1200
- SetOption.CommandKey = SlotKey;
1203
+ AddV_Slot(DomName, SlotKey, Option) {
1204
+ let SetOption = this.$ConvertCommandOption(DomName, Option);
1205
+ if (SlotKey != null)
1206
+ SetOption.CommandKey = SlotKey;
1201
1207
  this.$AddCommand(DomName, `v-slot`, SetOption);
1202
1208
  return this;
1203
1209
  }
@@ -1336,77 +1342,8 @@ export class VueCommand extends VueStore {
1336
1342
  RootNode = TreeRoot;
1337
1343
  let RootPaths = UsingRootNode ? [] : this.Paths(TreeRoot);
1338
1344
  this.$ParseTreeSet(RootPaths, TreeSet, AllSetInfo);
1339
- let CommandMap = {
1340
- 'v-text': (Info, Option) => {
1341
- Model.AddV_Text(Option.TargetDom, Option.TargetValue);
1342
- },
1343
- 'v-model': (Info, Option) => {
1344
- if (typeof (Info.StoreValue) == 'function') {
1345
- Model.$Error(`v-model command value must be a string or string[], path: ${this.ToJoin(Info.DomPaths)}`);
1346
- return;
1347
- }
1348
- Model.AddV_Model(Option.TargetDom, Option.TargetPath, {
1349
- ModelValue: Info.CommandKey,
1350
- });
1351
- },
1352
- 'v-for': (Info, Option) => {
1353
- Model.AddV_For(Option.TargetDom, Option.TargetValue, Info.CommandKey);
1354
- },
1355
- 'v-if': (Info, Option) => {
1356
- Model.AddV_If(Option.TargetDom, Option.TargetValue);
1357
- },
1358
- 'v-else-if': (Info, Option) => {
1359
- Model.AddV_ElseIf(Option.TargetDom, Option.TargetValue);
1360
- },
1361
- 'v-else': (Info, Option) => {
1362
- Model.AddV_Else(Option.TargetDom);
1363
- },
1364
- 'v-show': (Info, Option) => {
1365
- Model.AddV_Show(Option.TargetDom, Option.TargetValue);
1366
- },
1367
- 'v-bind': (Info, Option) => {
1368
- if (!Option.TargetValue)
1369
- return;
1370
- Model.AddV_Bind(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Params);
1371
- },
1372
- 'v-on': (Info, Option) => {
1373
- Model.AddV_On(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Params);
1374
- },
1375
- 'v-slot': (Info, Option) => {
1376
- if (Array.isArray(Info.StoreValue) || typeof (Info.StoreValue) == 'function') {
1377
- Model.$Error(`v-slot command value must be a string, path: ${this.ToJoin(Info.DomPaths)}`);
1378
- return;
1379
- }
1380
- Model.AddV_Slot(Option.TargetDom, Info.CommandKey, Option.TargetPath);
1381
- },
1382
- 'v-on-mounted': (Info, Option) => {
1383
- Model.AddV_OnMounted(Option.TargetDom, Option.TargetValue, Info.CommandKey);
1384
- },
1385
- 'v-on-unmounted': (Info, Option) => {
1386
- Model.AddV_OnUnMounted(Option.TargetDom, Option.TargetValue, Info.CommandKey);
1387
- },
1388
- 'watch': (Info, Option) => {
1389
- if (typeof (Info.StoreValue) != 'function') {
1390
- Model.$Error(`watch command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
1391
- return;
1392
- }
1393
- Model.AddV_Watch(Info.DomPaths, Info.StoreValue);
1394
- },
1395
- 'func': (Info, Option) => {
1396
- if (typeof (Info.StoreValue) != 'function') {
1397
- Model.$Error(`func command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
1398
- return;
1399
- }
1400
- Model.AddV_Function(['event', ...Info.DomPaths, Info.CommandKey], Info.StoreValue);
1401
- },
1402
- 'using': (Info, Option) => {
1403
- if (typeof (Info.StoreValue) === 'function') {
1404
- Info.StoreValue(Info.DomPaths, Info.Nodes);
1405
- }
1406
- }
1407
- };
1408
1345
  for (let Info of AllSetInfo) {
1409
- let ActionSet = CommandMap[Info.Command];
1346
+ let ActionSet = this.$CommandMap[Info.Command];
1410
1347
  if (ActionSet == null) {
1411
1348
  Model.$Error(`${Info.Command} command is not allowed, path: ${this.ToJoin(Info.DomPaths)}`);
1412
1349
  continue;
@@ -1430,15 +1367,38 @@ export class VueCommand extends VueStore {
1430
1367
  let TargetDom = NeedQuery ? Info.Nodes : Info.DomPaths;
1431
1368
  let TargetPath = [];
1432
1369
  let TargetValue;
1433
- if (typeof (Info.StoreValue) != 'function') {
1434
- if (Option?.UseTreePath)
1435
- TargetPath = [...Info.TreePaths];
1436
- if (Option?.UseDomStore || Info.StoreValue == '.')
1437
- TargetPath.push(Info.DomName);
1438
- else if (Info.StoreValue != null && Info.StoreValue != '')
1439
- TargetPath = this.Paths(TargetPath, Info.StoreValue);
1370
+ if (typeof Info.StoreValue === 'function') {
1371
+ TargetValue = {
1372
+ Target: Info.StoreValue,
1373
+ FuncArgs: Info.Args,
1374
+ };
1375
+ }
1376
+ else {
1377
+ if (typeof Info.StoreValue === 'string' || Array.isArray(Info.StoreValue)) {
1378
+ Info.StoreValue = Model.ToJoin(Info.StoreValue);
1379
+ if (Option?.UseTreePath)
1380
+ TargetPath = [...Info.TreePaths];
1381
+ if (Option?.UseDomStore || Info.StoreValue == '.')
1382
+ TargetPath.push(Info.DomName);
1383
+ else if (Info.StoreValue != null && Info.StoreValue != '')
1384
+ TargetPath = this.Paths(TargetPath, Info.StoreValue);
1385
+ TargetValue = TargetPath.length > 0 ? TargetPath : Info.StoreValue;
1386
+ }
1387
+ else {
1388
+ let NewStoreValue = {
1389
+ Target: Info.StoreValue?.TargetFunc,
1390
+ FuncArgs: Info.StoreValue?.Args,
1391
+ };
1392
+ TargetValue = NewStoreValue;
1393
+ if (Info.StoreValue?.Args != null) {
1394
+ let Args = Model.ToJoin(Info.StoreValue.Args);
1395
+ if (Info.CommandKey == null || Info.CommandKey == '')
1396
+ Info.CommandKey = Args;
1397
+ else
1398
+ Info.CommandKey = Model.ToJoin([Info.CommandKey, Args], ', ');
1399
+ }
1400
+ }
1440
1401
  }
1441
- TargetValue = TargetPath.length > 0 ? TargetPath : Info.StoreValue;
1442
1402
  if (TargetValue == '')
1443
1403
  continue;
1444
1404
  ActionSet(Info, {
@@ -1450,76 +1410,153 @@ export class VueCommand extends VueStore {
1450
1410
  return this;
1451
1411
  }
1452
1412
  $ParseTreeSet(Paths, TreeSet, Result) {
1413
+ const TreeNodeReges = /^:(?<next>.+)$/;
1453
1414
  let AllKeys = Object.keys(TreeSet);
1454
- let ParamRegex = /^(.+?)\(([^)]*)\)$/;
1455
1415
  for (let i = 0; i < AllKeys.length; i++) {
1456
1416
  let Command = AllKeys[i];
1457
1417
  let SetPair = TreeSet[Command];
1458
1418
  let DomPaths = [...Paths];
1459
1419
  let TreePaths = [...Paths];
1460
1420
  let DomName = TreePaths.pop();
1461
- if (!Command.includes(':')) {
1462
- let HasParams = Command.match(ParamRegex);
1463
- let CommandKey = null;
1464
- if (HasParams && HasParams.length >= 3) {
1465
- Command = HasParams[1];
1466
- CommandKey = HasParams[2];
1467
- }
1468
- Result.push({
1469
- Command: Command,
1470
- StoreValue: SetPair,
1471
- TreePaths: TreePaths,
1472
- DomPaths: DomPaths,
1473
- DomName: DomName,
1474
- CommandKey: CommandKey,
1475
- });
1476
- continue;
1477
- }
1478
- let Commands = Command.split(':');
1479
- if (Command.length < 2) {
1480
- Model.$Error(`command ${Command} invalid`);
1481
- continue;
1482
- }
1483
- Command = Commands.shift();
1484
- let Params = null;
1485
- if (Commands.length > 0) {
1486
- let LastCommand = Commands.pop();
1487
- let HasParams = LastCommand.match(ParamRegex);
1488
- if (HasParams && HasParams.length >= 3) {
1489
- Commands.push(HasParams[1]);
1490
- Params = HasParams[2];
1491
- }
1492
- else
1493
- Commands.push(LastCommand);
1494
- }
1495
- let NextDomName = Model.ToJoin(Commands, ':');
1496
- if (Command == '') {
1497
- if (typeof SetPair != 'function')
1498
- this.$ParseTreeSet([...Paths, NextDomName], SetPair, Result);
1499
- else {
1421
+ let TreeNodeResult = Command.match(TreeNodeReges);
1422
+ if (TreeNodeResult) {
1423
+ let NextDomName = TreeNodeResult.groups.next;
1424
+ if (typeof SetPair === 'function') {
1500
1425
  Result.push({
1501
1426
  Command: 'using',
1502
- CommandKey: null,
1503
1427
  StoreValue: SetPair,
1504
1428
  TreePaths: [...DomPaths],
1505
1429
  DomPaths: [...DomPaths, NextDomName],
1506
1430
  DomName: NextDomName,
1507
- Params: Params,
1508
1431
  });
1509
1432
  }
1433
+ else {
1434
+ this.$ParseTreeSet([...Paths, NextDomName], SetPair, Result);
1435
+ }
1510
1436
  continue;
1511
1437
  }
1438
+ let GetCommandPart = (FindCommand, StartChar, EndChar) => {
1439
+ if (!FindCommand.includes(StartChar) || !FindCommand.includes(EndChar))
1440
+ return null;
1441
+ let StartIndex = FindCommand.indexOf(StartChar);
1442
+ let EndIndex = FindCommand.lastIndexOf(EndChar);
1443
+ let Result = FindCommand.slice(StartIndex + 1, EndIndex).trim();
1444
+ return Result?.trim();
1445
+ };
1446
+ let GetCommandWithKey = (FindCommand) => {
1447
+ let ArgsStart = null;
1448
+ let ForKeyStart = null;
1449
+ if (FindCommand.includes('('))
1450
+ ArgsStart = FindCommand.indexOf('(');
1451
+ if (FindCommand.includes('<'))
1452
+ ForKeyStart = FindCommand.indexOf('<');
1453
+ let CommandWithKey = null;
1454
+ if (ArgsStart == null && ForKeyStart == null) {
1455
+ CommandWithKey = FindCommand;
1456
+ }
1457
+ else if (ArgsStart == null || ForKeyStart == null) {
1458
+ let MinIndex = ArgsStart ?? ForKeyStart;
1459
+ CommandWithKey = FindCommand.slice(0, MinIndex);
1460
+ }
1461
+ else {
1462
+ let MinIndex = Math.min(ArgsStart, ForKeyStart);
1463
+ CommandWithKey = FindCommand.slice(0, MinIndex);
1464
+ }
1465
+ let Command = CommandWithKey;
1466
+ let CommandKey = null;
1467
+ if (CommandWithKey.includes(':')) {
1468
+ let CommandKeyStart = Command.indexOf(':');
1469
+ Command = CommandWithKey.slice(0, CommandKeyStart);
1470
+ CommandKey = CommandWithKey.slice(CommandKeyStart + 1);
1471
+ }
1472
+ return {
1473
+ Command: Command?.trim(),
1474
+ CommandKey: CommandKey?.trim(),
1475
+ };
1476
+ };
1477
+ let Args = GetCommandPart(Command, '(', ')');
1478
+ let ForKey = GetCommandPart(Command, '<', '>');
1479
+ let CommandWithKey = GetCommandWithKey(Command);
1512
1480
  Result.push({
1513
- Command: Command,
1514
- CommandKey: NextDomName,
1481
+ Command: CommandWithKey?.Command,
1482
+ CommandKey: CommandWithKey?.CommandKey,
1483
+ ForKey: ForKey,
1484
+ Args: Args,
1515
1485
  StoreValue: SetPair,
1516
1486
  TreePaths: TreePaths,
1517
1487
  DomPaths: DomPaths,
1518
1488
  DomName: DomName,
1519
- Params: Params,
1520
1489
  });
1490
+ continue;
1521
1491
  }
1522
1492
  }
1493
+ $SetupCommandMap() {
1494
+ this.$CommandMap = {
1495
+ 'v-text': (Info, Option) => {
1496
+ Model.AddV_Text(Option.TargetDom, Option.TargetValue);
1497
+ },
1498
+ 'v-model': (Info, Option) => {
1499
+ if (typeof (Info.StoreValue) == 'function') {
1500
+ Model.$Error(`v-model command value must be a string or string[], path: ${this.ToJoin(Info.DomPaths)}`);
1501
+ return;
1502
+ }
1503
+ Model.AddV_Model(Option.TargetDom, Option.TargetPath, {
1504
+ ModelValue: Info.CommandKey,
1505
+ });
1506
+ },
1507
+ 'v-for': (Info, Option) => {
1508
+ Model.AddV_For(Option.TargetDom, Option.TargetValue, Info.ForKey);
1509
+ },
1510
+ 'v-if': (Info, Option) => {
1511
+ Model.AddV_If(Option.TargetDom, Option.TargetValue);
1512
+ },
1513
+ 'v-else-if': (Info, Option) => {
1514
+ Model.AddV_ElseIf(Option.TargetDom, Option.TargetValue);
1515
+ },
1516
+ 'v-else': (Info, Option) => {
1517
+ Model.AddV_Else(Option.TargetDom);
1518
+ },
1519
+ 'v-show': (Info, Option) => {
1520
+ Model.AddV_Show(Option.TargetDom, Option.TargetValue);
1521
+ },
1522
+ 'v-bind': (Info, Option) => {
1523
+ if (!Option.TargetValue)
1524
+ return;
1525
+ Model.AddV_Bind(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Args);
1526
+ },
1527
+ 'v-on': (Info, Option) => {
1528
+ Model.AddV_On(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Args);
1529
+ },
1530
+ 'v-slot': (Info, Option) => {
1531
+ Model.AddV_Slot(Option.TargetDom, Info.CommandKey, Option.TargetValue);
1532
+ },
1533
+ 'v-on-mounted': (Info, Option) => {
1534
+ Model.AddV_OnMounted(Option.TargetDom, Option.TargetValue, Info.Args);
1535
+ },
1536
+ 'v-on-unmounted': (Info, Option) => {
1537
+ Model.AddV_OnUnMounted(Option.TargetDom, Option.TargetValue, Info.Args);
1538
+ },
1539
+ 'watch': (Info, Option) => {
1540
+ if (typeof (Info.StoreValue) != 'function') {
1541
+ Model.$Error(`watch command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
1542
+ return;
1543
+ }
1544
+ Model.AddV_Watch(Info.DomPaths, Info.StoreValue);
1545
+ },
1546
+ 'func': (Info, Option) => {
1547
+ if (typeof (Info.StoreValue) != 'function') {
1548
+ Model.$Error(`func command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
1549
+ return;
1550
+ }
1551
+ Model.AddV_Function(['event', ...Info.DomPaths, Info.CommandKey], Info.StoreValue);
1552
+ },
1553
+ 'using': (Info, Option) => {
1554
+ if (typeof (Info.StoreValue) === 'function') {
1555
+ Info.StoreValue(Info.DomPaths, Info.Nodes);
1556
+ }
1557
+ }
1558
+ };
1559
+ }
1523
1560
  AddV_Property(PropertyPath, Option) {
1524
1561
  return this.AddV_PropertyFrom(this.Store, PropertyPath, Option);
1525
1562
  }
@@ -1627,11 +1664,7 @@ export class VueCommand extends VueStore {
1627
1664
  Target = this.$GenerateEventFunction(FuncDomName, Target, Command);
1628
1665
  if (Option.FuncArgs) {
1629
1666
  let Args = this.ToJoin(Option.FuncArgs, ',');
1630
- if (!/^\(/.test(Args))
1631
- Args = `(${Args}`;
1632
- if (!/\)$/.test(Args))
1633
- Args += ')';
1634
- Target += Args;
1667
+ Target += `(${Args})`;
1635
1668
  }
1636
1669
  else if (Option.FuncAction) {
1637
1670
  Target += `()`;