|
1 | 1 | /** |
2 | 2 | * Interjs |
3 | | - * Version - 2.1.3 |
| 3 | + * Version - 2.1.4 |
4 | 4 | * MIT LICENSED BY - Denis Power |
5 | 5 | * Repo - https://github.com/interjs/inter |
6 | | - * 2021-2023 |
| 6 | + * 2021 - 2023 |
7 | 7 | * GENERATED BY INTER GLOBAL BUILDER |
8 | 8 | * |
9 | 9 | */ |
|
51 | 51 | one or more of those options as plain Javascript object.`); |
52 | 52 | } |
53 | 53 |
|
| 54 | + function runIllegalAttrsPropWarning(prop) { |
| 55 | + const styleProp = `You should not use the style attribute(in attrs object) to create styles for the element, |
| 56 | + use the "styles" object instead, like: |
| 57 | +
|
| 58 | + { |
| 59 | + tag: "p", text: "Some text", styles: { color: "green" } |
| 60 | + } |
| 61 | +`; |
| 62 | + |
| 63 | + const event = `You shoud not use "${prop}" as an attribute name, it seems to be a dom event, |
| 64 | + use it as property of the "events" object, like: |
| 65 | +
|
| 66 | + { |
| 67 | + tag: "button", text: "Click me", events: { ${prop}: () => { //Some code here } } |
| 68 | + } |
| 69 | + `; |
| 70 | + |
| 71 | + consW(prop.startsWith("on") ? event : styleProp); |
| 72 | + } |
| 73 | + |
54 | 74 | function runCanNotDefineReactivePropWarning() { |
55 | 75 | consW(`Inter failed to define reactivity |
56 | 76 | in a plain Javascript object, because it is not configurable.`); |
|
1645 | 1665 | Object.entries(attrs).forEach((attr) => { |
1646 | 1666 | // eslint-disable-next-line prefer-const |
1647 | 1667 | let [name, value] = attr; |
| 1668 | + let hasWarning = false; |
1648 | 1669 | const specialAttrs = new Set(["value", "currentTime", "checked"]); |
1649 | 1670 |
|
| 1671 | + if ((name.startsWith("on") && validDomEvent(name)) || name == "style") { |
| 1672 | + runIllegalAttrsPropWarning(name); |
| 1673 | + hasWarning = true; |
| 1674 | + } |
| 1675 | + |
1650 | 1676 | const setAttr = (attrValue) => { |
1651 | 1677 | if (isDefined(attrValue) && !isFalse(attrValue)) { |
1652 | 1678 | if (!specialAttrs.has(name)) container.setAttribute(name, attrValue); |
|
1655 | 1681 | container.template.attrs[name] = attrValue; |
1656 | 1682 | }; |
1657 | 1683 |
|
1658 | | - if (isCallable(value)) { |
1659 | | - value = value(); |
| 1684 | + if (!hasWarning) { |
| 1685 | + if (isCallable(value)) { |
| 1686 | + value = value(); |
1660 | 1687 |
|
1661 | | - setAttr(value); |
1662 | | - } else { |
1663 | | - setAttr(value); |
| 1688 | + setAttr(value); |
| 1689 | + } else { |
| 1690 | + setAttr(value); |
| 1691 | + } |
1664 | 1692 | } |
1665 | 1693 | }); |
1666 | 1694 | } |
|
3288 | 3316 | window.template = template; |
3289 | 3317 | window.toAttrs = toAttrs; |
3290 | 3318 | window.Backend = Backend; |
3291 | | - console.log("The global version 2.1.3 of Inter was loaded successfully."); |
| 3319 | + console.log("The global version 2.1.4 of Inter was loaded successfully."); |
3292 | 3320 | })(); |
0 commit comments