regor 1.4.3 → 1.4.5

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.
@@ -463,10 +463,13 @@ var IfBinder = class {
463
463
  }
464
464
  __bindAll(element) {
465
465
  const isIfElement = element.hasAttribute(this.__if);
466
- const elements = findElements(element, this.__ifSelector);
467
- for (const el of elements) {
468
- this.__bind(el);
469
- }
466
+ if (isIfElement) this.__bind(element);
467
+ this.__binder.__componentBinder.__forEachBindableDescendant(
468
+ element,
469
+ (el) => {
470
+ if (el.hasAttribute(this.__if)) this.__bind(el);
471
+ }
472
+ );
470
473
  return isIfElement;
471
474
  }
472
475
  __isProcessedOrMark(el) {
@@ -738,6 +741,12 @@ var teleportDirective = {
738
741
  mount: () => void 0
739
742
  };
740
743
 
744
+ // src/common/class-tokens.ts
745
+ var toClassTokens = (value) => {
746
+ const trimmed = value.trim();
747
+ return trimmed ? trimmed.split(/\s+/) : [];
748
+ };
749
+
741
750
  // src/composition/callMounted.ts
742
751
  var callMounted = (context) => {
743
752
  var _a, _b;
@@ -1252,8 +1261,16 @@ var ComponentBinder = class {
1252
1261
  }
1253
1262
  return false;
1254
1263
  }
1264
+ __isNamedSlotTemplateShortcut(node) {
1265
+ if (!isTemplate(node)) return false;
1266
+ const attributeNames = node.getAttributeNames();
1267
+ if (node.hasAttribute("name")) return true;
1268
+ return attributeNames.some((x) => x.startsWith("#"));
1269
+ }
1270
+ __isDefaultSlotTemplateShortcut(node) {
1271
+ return isTemplate(node) && node.getAttributeNames().length === 0;
1272
+ }
1255
1273
  __unwrapComponents(element) {
1256
- var _a;
1257
1274
  const binder = this.__binder;
1258
1275
  const parser = binder.__parser;
1259
1276
  const registeredComponents = binder.__config.__components;
@@ -1262,16 +1279,9 @@ var ComponentBinder = class {
1262
1279
  return;
1263
1280
  }
1264
1281
  const contextComponents = parser.__getComponents();
1265
- const contextComponentSelectors = parser.__getComponentSelectors();
1266
- const registeredSelector = this.__getRegisteredComponentSelector(registeredComponents);
1267
- const selector = [
1268
- ...registeredSelector ? [registeredSelector] : [],
1269
- ...contextComponentSelectors,
1270
- ...contextComponentSelectors.map(hyphenate)
1271
- ].join(",");
1282
+ const selector = this.__getComponentSelector();
1272
1283
  if (isNullOrWhitespace(selector)) return;
1273
- const list = element.querySelectorAll(selector);
1274
- const components = ((_a = element.matches) == null ? void 0 : _a.call(element, selector)) ? [element, ...list] : list;
1284
+ const components = this.__collectTopLevelComponentHosts(element, selector);
1275
1285
  for (const component of components) {
1276
1286
  if (component.hasAttribute(binder.__pre)) continue;
1277
1287
  const parent = component.parentNode;
@@ -1345,7 +1355,7 @@ var ComponentBinder = class {
1345
1355
  };
1346
1356
  const capturedContext = [...parser.__capture()];
1347
1357
  const createComponentCtx = () => {
1348
- var _a2;
1358
+ var _a;
1349
1359
  const props = getProps(component, capturedContext);
1350
1360
  const head2 = new ComponentHead(
1351
1361
  props,
@@ -1355,8 +1365,8 @@ var ComponentBinder = class {
1355
1365
  endOfComponent
1356
1366
  );
1357
1367
  const componentCtx2 = useScope(() => {
1358
- var _a3;
1359
- return (_a3 = registeredComponent.context(head2)) != null ? _a3 : {};
1368
+ var _a2;
1369
+ return (_a2 = registeredComponent.context(head2)) != null ? _a2 : {};
1360
1370
  }).context;
1361
1371
  if (head2.autoProps) {
1362
1372
  for (const [key, propsValue] of Object.entries(props)) {
@@ -1380,7 +1390,7 @@ var ComponentBinder = class {
1380
1390
  }
1381
1391
  } else componentCtx2[key] = propsValue;
1382
1392
  }
1383
- (_a2 = head2.onAutoPropsAssigned) == null ? void 0 : _a2.call(head2);
1393
+ (_a = head2.onAutoPropsAssigned) == null ? void 0 : _a.call(head2);
1384
1394
  }
1385
1395
  return { componentCtx: componentCtx2, head: head2 };
1386
1396
  };
@@ -1389,6 +1399,7 @@ var ComponentBinder = class {
1389
1399
  const len = childNodes.length;
1390
1400
  const isEmptyComponent = component.childNodes.length === 0;
1391
1401
  const expandSlot = (slot) => {
1402
+ var _a;
1392
1403
  const parent2 = slot.parentElement;
1393
1404
  let name = slot.name;
1394
1405
  if (isNullOrWhitespace(name)) {
@@ -1418,9 +1429,12 @@ var ComponentBinder = class {
1418
1429
  `template[name='${name}'], template[\\#${name}]`
1419
1430
  );
1420
1431
  if (!compTemplate && name === "default") {
1421
- compTemplate = component.querySelector("template:not([name])");
1422
- if (compTemplate && compTemplate.getAttributeNames().filter((x) => x.startsWith("#")).length > 0)
1423
- compTemplate = null;
1432
+ const unnamedTemplates = component.querySelectorAll(
1433
+ "template:not([name])"
1434
+ );
1435
+ compTemplate = (_a = [...unnamedTemplates].find(
1436
+ (x) => this.__isDefaultSlotTemplateShortcut(x)
1437
+ )) != null ? _a : null;
1424
1438
  }
1425
1439
  const createSwitchContext = (childNodes2) => {
1426
1440
  if (!head.enableSwitch) return;
@@ -1456,7 +1470,7 @@ var ComponentBinder = class {
1456
1470
  return;
1457
1471
  }
1458
1472
  const childNodes2 = [...getChildNodes(component)].filter(
1459
- (x) => !isTemplate(x)
1473
+ (x) => !this.__isNamedSlotTemplateShortcut(x)
1460
1474
  );
1461
1475
  for (const slotChild of childNodes2) {
1462
1476
  parent2.insertBefore(slotChild, slot);
@@ -1502,7 +1516,8 @@ var ComponentBinder = class {
1502
1516
  continue;
1503
1517
  const value = component.getAttribute(attrName);
1504
1518
  if (attrName === "class") {
1505
- inheritor.classList.add(...value.split(" "));
1519
+ const classTokens = toClassTokens(value);
1520
+ if (classTokens.length > 0) inheritor.classList.add(...classTokens);
1506
1521
  } else if (attrName === "style") {
1507
1522
  const inheritorStyle = inheritor.style;
1508
1523
  const componentStyle = component.style;
@@ -1541,6 +1556,65 @@ var ComponentBinder = class {
1541
1556
  parser.__scoped(capturedContext, bindComponent);
1542
1557
  }
1543
1558
  }
1559
+ __getComponentSelector() {
1560
+ const binder = this.__binder;
1561
+ const parser = binder.__parser;
1562
+ const registeredComponents = binder.__config.__components;
1563
+ const contextComponentSelectors = parser.__getComponentSelectors();
1564
+ const registeredSelector = this.__getRegisteredComponentSelector(registeredComponents);
1565
+ return [
1566
+ ...registeredSelector ? [registeredSelector] : [],
1567
+ ...contextComponentSelectors,
1568
+ ...contextComponentSelectors.map(hyphenate)
1569
+ ].join(",");
1570
+ }
1571
+ __collectTopLevelComponentHosts(root, selector) {
1572
+ var _a;
1573
+ const result = [];
1574
+ if (isNullOrWhitespace(selector)) return result;
1575
+ if ((_a = root.matches) == null ? void 0 : _a.call(root, selector)) return [root];
1576
+ const stack = this.__getChildElements(root).reverse();
1577
+ while (stack.length > 0) {
1578
+ const current = stack.pop();
1579
+ if (current.matches(selector)) {
1580
+ result.push(current);
1581
+ continue;
1582
+ }
1583
+ stack.push(...this.__getChildElements(current).reverse());
1584
+ }
1585
+ return result;
1586
+ }
1587
+ __forEachBindableDescendant(root, action) {
1588
+ const selector = this.__getComponentSelector();
1589
+ const stack = this.__getChildElements(root).reverse();
1590
+ while (stack.length > 0) {
1591
+ const current = stack.pop();
1592
+ action(current);
1593
+ if (!isNullOrWhitespace(selector) && current.matches(selector)) continue;
1594
+ stack.push(...this.__getChildElements(current).reverse());
1595
+ }
1596
+ }
1597
+ __getChildElements(root) {
1598
+ const children = root == null ? void 0 : root.children;
1599
+ if ((children == null ? void 0 : children.length) != null) {
1600
+ const result = [];
1601
+ for (let i = 0; i < children.length; ++i) {
1602
+ const child = children[i];
1603
+ if (isElement(child)) result.push(child);
1604
+ }
1605
+ return result;
1606
+ }
1607
+ const childNodes = root == null ? void 0 : root.childNodes;
1608
+ if ((childNodes == null ? void 0 : childNodes.length) != null) {
1609
+ const result = [];
1610
+ for (let i = 0; i < childNodes.length; ++i) {
1611
+ const child = childNodes[i];
1612
+ if (isElement(child)) result.push(child);
1613
+ }
1614
+ return result;
1615
+ }
1616
+ return [];
1617
+ }
1544
1618
  };
1545
1619
 
1546
1620
  // src/bind/DirectiveCollector.ts
@@ -1633,10 +1707,10 @@ var DirectiveCollector = class {
1633
1707
  };
1634
1708
  processNode(element);
1635
1709
  if (!isRecursive || !element.firstElementChild) return map;
1636
- const nodes = element.querySelectorAll("*");
1637
- for (const node of nodes) {
1638
- processNode(node);
1639
- }
1710
+ this.__binder.__componentBinder.__forEachBindableDescendant(
1711
+ element,
1712
+ processNode
1713
+ );
1640
1714
  return map;
1641
1715
  }
1642
1716
  };
@@ -1654,17 +1728,19 @@ var DynamicBinder = class {
1654
1728
  constructor(binder) {
1655
1729
  __publicField(this, "__binder");
1656
1730
  __publicField(this, "__is");
1657
- __publicField(this, "__isSelector");
1658
1731
  this.__binder = binder;
1659
1732
  this.__is = binder.__config.__builtInNames.is;
1660
- this.__isSelector = toSelector(this.__is) + ", [is]";
1661
1733
  }
1662
1734
  __bindAll(element) {
1663
1735
  const isComponentElement = element.hasAttribute(this.__is);
1664
- const elements = findElements(element, this.__isSelector);
1665
- for (const el of elements) {
1666
- this.__bind(el);
1667
- }
1736
+ if (isComponentElement || element.hasAttribute("is"))
1737
+ this.__bind(element);
1738
+ this.__binder.__componentBinder.__forEachBindableDescendant(
1739
+ element,
1740
+ (el) => {
1741
+ if (el.hasAttribute(this.__is) || el.hasAttribute("is")) this.__bind(el);
1742
+ }
1743
+ );
1668
1744
  return isComponentElement;
1669
1745
  }
1670
1746
  __bind(el) {
@@ -2141,10 +2217,13 @@ var _ForBinder = class _ForBinder {
2141
2217
  }
2142
2218
  __bindAll(element) {
2143
2219
  const isForElement = element.hasAttribute(this.__for);
2144
- const elements = findElements(element, this.__forSelector);
2145
- for (const el of elements) {
2146
- this.__bindFor(el);
2147
- }
2220
+ if (isForElement) this.__bindFor(element);
2221
+ this.__binder.__componentBinder.__forEachBindableDescendant(
2222
+ element,
2223
+ (el) => {
2224
+ if (el.hasAttribute(this.__for)) this.__bindFor(el);
2225
+ }
2226
+ );
2148
2227
  return isForElement;
2149
2228
  }
2150
2229
  __isProcessedOrMark(el) {
@@ -2870,11 +2949,14 @@ var patchClass = (el, next, prev) => {
2870
2949
  } else {
2871
2950
  if (isClassString) {
2872
2951
  if (prev !== next) {
2873
- if (isPrevClassString) classList.remove(...prev.trim().split(/\s+/));
2874
- classList.add(...next.trim().split(/\s+/));
2952
+ const prevTokens = isPrevClassString ? toClassTokens(prev) : [];
2953
+ const nextTokens = toClassTokens(next);
2954
+ if (prevTokens.length > 0) classList.remove(...prevTokens);
2955
+ if (nextTokens.length > 0) classList.add(...nextTokens);
2875
2956
  }
2876
2957
  } else if (prev) {
2877
- if (isPrevClassString) classList.remove(...prev.trim().split(/\s+/));
2958
+ const prevTokens = isPrevClassString ? toClassTokens(prev) : [];
2959
+ if (prevTokens.length > 0) classList.remove(...prevTokens);
2878
2960
  }
2879
2961
  }
2880
2962
  };