@joist/templating 4.7.0 → 4.7.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.
- package/package.json +1 -1
- package/target/lib/bind.d.ts +10 -0
- package/target/lib/bind.d.ts.map +1 -0
- package/target/lib/bind.js +50 -0
- package/target/lib/bind.js.map +1 -0
- package/target/lib/bind.test.d.ts +2 -0
- package/target/lib/bind.test.d.ts.map +1 -0
- package/target/lib/bind.test.js +110 -0
- package/target/lib/bind.test.js.map +1 -0
- package/target/lib/define.d.ts +17 -0
- package/target/lib/define.d.ts.map +1 -0
- package/target/lib/define.js +14 -0
- package/target/lib/define.js.map +1 -0
- package/target/lib/elements/async.element.d.ts +14 -0
- package/target/lib/elements/async.element.d.ts.map +1 -0
- package/target/lib/elements/async.element.js +168 -0
- package/target/lib/elements/async.element.js.map +1 -0
- package/target/lib/elements/async.element.test.d.ts +2 -0
- package/target/lib/elements/async.element.test.d.ts.map +1 -0
- package/target/lib/elements/async.element.test.js +191 -0
- package/target/lib/elements/async.element.test.js.map +1 -0
- package/target/lib/elements/bind.element.d.ts +14 -0
- package/target/lib/elements/bind.element.d.ts.map +1 -0
- package/target/lib/elements/bind.element.js +180 -0
- package/target/lib/elements/bind.element.js.map +1 -0
- package/target/lib/elements/bind.element.test.d.ts +2 -0
- package/target/lib/elements/bind.element.test.d.ts.map +1 -0
- package/target/lib/elements/bind.element.test.js +153 -0
- package/target/lib/elements/bind.element.test.js.map +1 -0
- package/target/lib/elements/for.element.d.ts +16 -0
- package/target/lib/elements/for.element.d.ts.map +1 -0
- package/target/lib/elements/for.element.js +259 -0
- package/target/lib/elements/for.element.js.map +1 -0
- package/target/lib/elements/for.element.test.d.ts +2 -0
- package/target/lib/elements/for.element.test.d.ts.map +1 -0
- package/target/lib/elements/for.element.test.js +232 -0
- package/target/lib/elements/for.element.test.js.map +1 -0
- package/target/lib/elements/if.element.d.ts +10 -0
- package/target/lib/elements/if.element.d.ts.map +1 -0
- package/target/lib/elements/if.element.js +145 -0
- package/target/lib/elements/if.element.js.map +1 -0
- package/target/lib/elements/if.element.test.d.ts +2 -0
- package/target/lib/elements/if.element.test.d.ts.map +1 -0
- package/target/lib/elements/if.element.test.js +309 -0
- package/target/lib/elements/if.element.test.js.map +1 -0
- package/target/lib/elements/scope.element.d.ts +4 -0
- package/target/lib/elements/scope.element.d.ts.map +1 -0
- package/target/lib/elements/scope.element.js +71 -0
- package/target/lib/elements/scope.element.js.map +1 -0
- package/target/lib/elements/scope.element.test.d.ts +2 -0
- package/target/lib/elements/scope.element.test.d.ts.map +1 -0
- package/target/lib/elements/scope.element.test.js +25 -0
- package/target/lib/elements/scope.element.test.js.map +1 -0
- package/target/lib/elements/value.element.d.ts +6 -0
- package/target/lib/elements/value.element.d.ts.map +1 -0
- package/target/lib/elements/value.element.js +96 -0
- package/target/lib/elements/value.element.js.map +1 -0
- package/target/lib/elements/value.element.test.d.ts +2 -0
- package/target/lib/elements/value.element.test.d.ts.map +1 -0
- package/target/lib/elements/value.element.test.js +68 -0
- package/target/lib/elements/value.element.test.js.map +1 -0
- package/target/lib/events.d.ts +17 -0
- package/target/lib/events.d.ts.map +1 -0
- package/target/lib/events.js +10 -0
- package/target/lib/events.js.map +1 -0
- package/target/lib/expression.d.ts +65 -0
- package/target/lib/expression.d.ts.map +1 -0
- package/target/lib/expression.js +153 -0
- package/target/lib/expression.js.map +1 -0
- package/target/lib/expression.test.d.ts +2 -0
- package/target/lib/expression.test.d.ts.map +1 -0
- package/target/lib/expression.test.js +171 -0
- package/target/lib/expression.test.js.map +1 -0
- package/target/lib.d.ts +3 -0
- package/target/lib.d.ts.map +1 -0
- package/target/lib.js +3 -0
- package/target/lib.js.map +1 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import { attr, element, queryAll, css, html } from "@joist/element";
|
|
36
|
+
import { JoistValueEvent } from "../events.js";
|
|
37
|
+
import { JExpression } from "../expression.js";
|
|
38
|
+
let JoistIfElement = (() => {
|
|
39
|
+
let _classDecorators = [element({
|
|
40
|
+
// prettier-ignore
|
|
41
|
+
shadowDom: [css `:host{display: contents}`, html `<slot></slot>`],
|
|
42
|
+
})];
|
|
43
|
+
let _classDescriptor;
|
|
44
|
+
let _classExtraInitializers = [];
|
|
45
|
+
let _classThis;
|
|
46
|
+
let _classSuper = HTMLElement;
|
|
47
|
+
let _bind_decorators;
|
|
48
|
+
let _bind_initializers = [];
|
|
49
|
+
let _bind_extraInitializers = [];
|
|
50
|
+
let _target_decorators;
|
|
51
|
+
let _target_initializers = [];
|
|
52
|
+
let _target_extraInitializers = [];
|
|
53
|
+
let _dependsOn_decorators;
|
|
54
|
+
let _dependsOn_initializers = [];
|
|
55
|
+
let _dependsOn_extraInitializers = [];
|
|
56
|
+
var JoistIfElement = class extends _classSuper {
|
|
57
|
+
static { _classThis = this; }
|
|
58
|
+
static {
|
|
59
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
60
|
+
_bind_decorators = [attr()];
|
|
61
|
+
_target_decorators = [attr()];
|
|
62
|
+
_dependsOn_decorators = [attr({
|
|
63
|
+
name: "depends-on",
|
|
64
|
+
})];
|
|
65
|
+
__esDecorate(this, null, _bind_decorators, { kind: "accessor", name: "bind", static: false, private: false, access: { has: obj => "bind" in obj, get: obj => obj.bind, set: (obj, value) => { obj.bind = value; } }, metadata: _metadata }, _bind_initializers, _bind_extraInitializers);
|
|
66
|
+
__esDecorate(this, null, _target_decorators, { kind: "accessor", name: "target", static: false, private: false, access: { has: obj => "target" in obj, get: obj => obj.target, set: (obj, value) => { obj.target = value; } }, metadata: _metadata }, _target_initializers, _target_extraInitializers);
|
|
67
|
+
__esDecorate(this, null, _dependsOn_decorators, { kind: "accessor", name: "dependsOn", static: false, private: false, access: { has: obj => "dependsOn" in obj, get: obj => obj.dependsOn, set: (obj, value) => { obj.dependsOn = value; } }, metadata: _metadata }, _dependsOn_initializers, _dependsOn_extraInitializers);
|
|
68
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
69
|
+
JoistIfElement = _classThis = _classDescriptor.value;
|
|
70
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
71
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
72
|
+
}
|
|
73
|
+
#bind_accessor_storage = __runInitializers(this, _bind_initializers, "");
|
|
74
|
+
get bind() { return this.#bind_accessor_storage; }
|
|
75
|
+
set bind(value) { this.#bind_accessor_storage = value; }
|
|
76
|
+
#target_accessor_storage = (__runInitializers(this, _bind_extraInitializers), __runInitializers(this, _target_initializers, ""));
|
|
77
|
+
get target() { return this.#target_accessor_storage; }
|
|
78
|
+
set target(value) { this.#target_accessor_storage = value; }
|
|
79
|
+
#dependsOn_accessor_storage = (__runInitializers(this, _target_extraInitializers), __runInitializers(this, _dependsOn_initializers, ""));
|
|
80
|
+
get dependsOn() { return this.#dependsOn_accessor_storage; }
|
|
81
|
+
set dependsOn(value) { this.#dependsOn_accessor_storage = value; }
|
|
82
|
+
#templates = (__runInitializers(this, _dependsOn_extraInitializers), queryAll("template", this));
|
|
83
|
+
#shouldShowIf = null;
|
|
84
|
+
#target = this;
|
|
85
|
+
async connectedCallback() {
|
|
86
|
+
const templates = Array.from(this.#templates());
|
|
87
|
+
if (templates.length === 0) {
|
|
88
|
+
throw new Error("j-if requires at least one template element");
|
|
89
|
+
}
|
|
90
|
+
if (templates.length > 2) {
|
|
91
|
+
throw new Error("j-if can only have two template elements (if and else)");
|
|
92
|
+
}
|
|
93
|
+
if (templates.length === 2 && !templates.some((t) => t.hasAttribute("else"))) {
|
|
94
|
+
throw new Error("When using two templates, one must have the else attribute");
|
|
95
|
+
}
|
|
96
|
+
if (templates.length === 2 && templates[0].hasAttribute("else")) {
|
|
97
|
+
// Swap templates to ensure if template is first
|
|
98
|
+
const first = templates[0];
|
|
99
|
+
templates[0] = templates[1];
|
|
100
|
+
templates[1] = first;
|
|
101
|
+
}
|
|
102
|
+
const token = new JExpression(this.bind);
|
|
103
|
+
const root = this.getRootNode();
|
|
104
|
+
if (this.target) {
|
|
105
|
+
const result = root.querySelector(this.target);
|
|
106
|
+
if (result) {
|
|
107
|
+
this.#target = result;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (this.dependsOn) {
|
|
111
|
+
await Promise.all(this.dependsOn.split(",").map((tag) => window.customElements.whenDefined(tag)));
|
|
112
|
+
}
|
|
113
|
+
this.dispatchEvent(new JoistValueEvent(token, ({ newValue, oldValue, firstChange }) => {
|
|
114
|
+
if (firstChange || newValue !== oldValue) {
|
|
115
|
+
this.apply(token.evaluate(newValue), token.isNegated);
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
apply(value, isNegative) {
|
|
120
|
+
const shouldShowIf = isNegative ? !value : !!value;
|
|
121
|
+
if (shouldShowIf === this.#shouldShowIf) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.#shouldShowIf = shouldShowIf;
|
|
125
|
+
this.#clean();
|
|
126
|
+
const templates = this.#templates();
|
|
127
|
+
const templateToUse = this.#shouldShowIf ? templates[0] : templates[1];
|
|
128
|
+
if (templateToUse) {
|
|
129
|
+
const content = document.importNode(templateToUse.content, true);
|
|
130
|
+
this.#target.append(content);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
#clean() {
|
|
134
|
+
while (this.#target.lastChild && !(this.#target.lastChild instanceof HTMLTemplateElement)) {
|
|
135
|
+
this.#target.lastChild.remove();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
disconnectedCallback() {
|
|
139
|
+
this.#clean();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
return JoistIfElement = _classThis;
|
|
143
|
+
})();
|
|
144
|
+
export { JoistIfElement };
|
|
145
|
+
//# sourceMappingURL=if.element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"if.element.js","sourceRoot":"","sources":["../../../src/lib/elements/if.element.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;IAMlC,cAAc;4BAJ1B,OAAO,CAAC;YACP,kBAAkB;YAClB,SAAS,EAAE,CAAC,GAAG,CAAA,0BAA0B,EAAE,IAAI,CAAA,eAAe,CAAC;SAChE,CAAC;;;;sBACkC,WAAW;;;;;;;;;;8BAAnB,SAAQ,WAAW;;;;gCAC5C,IAAI,EAAE;kCAGN,IAAI,EAAE;qCAGN,IAAI,CAAC;oBACJ,IAAI,EAAE,YAAY;iBACnB,CAAC;YAPF,iKAAS,IAAI,6BAAJ,IAAI,mFAAM;YAGnB,uKAAS,MAAM,6BAAN,MAAM,uFAAM;YAKrB,gLAAS,SAAS,6BAAT,SAAS,6FAAM;YAV1B,6KAgGC;;;YAhGY,uDAAc;;QAEzB,qEAAgB,EAAE,EAAC;QAAnB,IAAS,IAAI,0CAAM;QAAnB,IAAS,IAAI,gDAAM;QAGnB,4HAAkB,EAAE,GAAC;QAArB,IAAS,MAAM,4CAAM;QAArB,IAAS,MAAM,kDAAM;QAKrB,oIAAqB,EAAE,GAAC;QAAxB,IAAS,SAAS,+CAAM;QAAxB,IAAS,SAAS,qDAAM;QAExB,UAAU,2DAAG,QAAQ,CAAsB,UAAU,EAAE,IAAI,CAAC,EAAC;QAC7D,aA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,EAAE,IAAI,CAAC,CAAC;gBAEjE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,MAAM;YACJ,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,YAAY,mBAAmB,CAAC,EAAE,CAAC;gBAC1F,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;YAClC,CAAC;QACH,CAAC;QAED,oBAAoB;YAClB,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,CAAC;;;;SA/FU,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"if.element.test.d.ts","sourceRoot":"","sources":["../../../src/lib/elements/if.element.test.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import "../define.js";
|
|
2
|
+
import { fixtureSync, html } from "@open-wc/testing";
|
|
3
|
+
import { assert } from "chai";
|
|
4
|
+
it("should render content when the bind value is truthy", () => {
|
|
5
|
+
const element = fixtureSync(html `
|
|
6
|
+
<div
|
|
7
|
+
@joist::value=${(e) => {
|
|
8
|
+
e.update({ oldValue: null, newValue: true });
|
|
9
|
+
}}
|
|
10
|
+
>
|
|
11
|
+
<j-if bind="test">
|
|
12
|
+
<template>Visible Content</template>
|
|
13
|
+
</j-if>
|
|
14
|
+
</div>
|
|
15
|
+
`);
|
|
16
|
+
assert.equal(element.textContent?.trim(), "Visible Content");
|
|
17
|
+
});
|
|
18
|
+
it("should not render content when the bind value is falsy", () => {
|
|
19
|
+
const element = fixtureSync(html `
|
|
20
|
+
<div
|
|
21
|
+
@joist::value=${(e) => {
|
|
22
|
+
e.update({ oldValue: null, newValue: true });
|
|
23
|
+
e.update({ oldValue: null, newValue: false });
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
<j-if bind="test">
|
|
27
|
+
<template>Visible Content</template>
|
|
28
|
+
</j-if>
|
|
29
|
+
</div>
|
|
30
|
+
`);
|
|
31
|
+
assert.equal(element.textContent?.trim(), "");
|
|
32
|
+
});
|
|
33
|
+
it("should handle negated tokens correctly", () => {
|
|
34
|
+
const element = fixtureSync(html `
|
|
35
|
+
<div
|
|
36
|
+
@joist::value=${(e) => {
|
|
37
|
+
e.update({ oldValue: null, newValue: false });
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
<j-if bind="!test">
|
|
41
|
+
<template>Visible Content</template>
|
|
42
|
+
</j-if>
|
|
43
|
+
</div>
|
|
44
|
+
`);
|
|
45
|
+
assert.equal(element.textContent?.trim(), "Visible Content");
|
|
46
|
+
});
|
|
47
|
+
it("should render else template when condition is falsy", () => {
|
|
48
|
+
const element = fixtureSync(html `
|
|
49
|
+
<div
|
|
50
|
+
@joist::value=${(e) => {
|
|
51
|
+
e.update({ oldValue: null, newValue: false });
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<j-if bind="test">
|
|
55
|
+
<template>If Content</template>
|
|
56
|
+
<template else>Else Content</template>
|
|
57
|
+
</j-if>
|
|
58
|
+
</div>
|
|
59
|
+
`);
|
|
60
|
+
assert.equal(element.textContent?.trim(), "Else Content");
|
|
61
|
+
});
|
|
62
|
+
it("should switch between if and else templates", () => {
|
|
63
|
+
const element = fixtureSync(html `
|
|
64
|
+
<div
|
|
65
|
+
@joist::value=${(e) => {
|
|
66
|
+
e.update({ oldValue: null, newValue: false });
|
|
67
|
+
e.update({ oldValue: false, newValue: true });
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<j-if bind="test">
|
|
71
|
+
<template>If Content</template>
|
|
72
|
+
<template else>Else Content</template>
|
|
73
|
+
</j-if>
|
|
74
|
+
</div>
|
|
75
|
+
`);
|
|
76
|
+
assert.equal(element.textContent?.trim(), "If Content");
|
|
77
|
+
});
|
|
78
|
+
it("should handle equality comparison", () => {
|
|
79
|
+
const element = fixtureSync(html `
|
|
80
|
+
<div
|
|
81
|
+
@joist::value=${(e) => {
|
|
82
|
+
e.update({ oldValue: null, newValue: { status: "active" } });
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<j-if bind="example.status == active">
|
|
86
|
+
<template>Status is Active</template>
|
|
87
|
+
</j-if>
|
|
88
|
+
</div>
|
|
89
|
+
`);
|
|
90
|
+
assert.equal(element.textContent?.trim(), "Status is Active");
|
|
91
|
+
});
|
|
92
|
+
it("should handle greater than comparison", () => {
|
|
93
|
+
const element = fixtureSync(html `
|
|
94
|
+
<div
|
|
95
|
+
@joist::value=${(e) => {
|
|
96
|
+
e.update({ oldValue: null, newValue: { count: 10 } });
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
<j-if bind="example.count > 5">
|
|
100
|
+
<template>Count is Greater Than 5</template>
|
|
101
|
+
</j-if>
|
|
102
|
+
</div>
|
|
103
|
+
`);
|
|
104
|
+
assert.equal(element.textContent?.trim(), "Count is Greater Than 5");
|
|
105
|
+
});
|
|
106
|
+
it("should handle less than comparison", () => {
|
|
107
|
+
const element = fixtureSync(html `
|
|
108
|
+
<div
|
|
109
|
+
@joist::value=${(e) => {
|
|
110
|
+
e.update({ oldValue: null, newValue: { score: 75 } });
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
<j-if bind="example.score < 100">
|
|
114
|
+
<template>Score is Less Than 100</template>
|
|
115
|
+
</j-if>
|
|
116
|
+
</div>
|
|
117
|
+
`);
|
|
118
|
+
assert.equal(element.textContent?.trim(), "Score is Less Than 100");
|
|
119
|
+
});
|
|
120
|
+
it("should handle nested path comparisons", () => {
|
|
121
|
+
const element = fixtureSync(html `
|
|
122
|
+
<div
|
|
123
|
+
@joist::value=${(e) => {
|
|
124
|
+
e.update({ oldValue: null, newValue: { user: { score: 150 } } });
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
<j-if bind="example.user.score > 100">
|
|
128
|
+
<template>User Score is Above 100</template>
|
|
129
|
+
</j-if>
|
|
130
|
+
</div>
|
|
131
|
+
`);
|
|
132
|
+
assert.equal(element.textContent?.trim(), "User Score is Above 100");
|
|
133
|
+
});
|
|
134
|
+
it("should handle negated comparisons", () => {
|
|
135
|
+
const element = fixtureSync(html `
|
|
136
|
+
<div
|
|
137
|
+
@joist::value=${(e) => {
|
|
138
|
+
e.update({ oldValue: null, newValue: { status: "inactive" } });
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
<j-if bind="!example.status == active">
|
|
142
|
+
<template>Status is Not Active</template>
|
|
143
|
+
</j-if>
|
|
144
|
+
</div>
|
|
145
|
+
`);
|
|
146
|
+
assert.equal(element.textContent?.trim(), "Status is Not Active");
|
|
147
|
+
});
|
|
148
|
+
it("should handle string number comparisons", () => {
|
|
149
|
+
const element = fixtureSync(html `
|
|
150
|
+
<div
|
|
151
|
+
@joist::value=${(e) => {
|
|
152
|
+
e.update({ oldValue: null, newValue: { count: "10" } });
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
<j-if bind="example.count > 5">
|
|
156
|
+
<template>String Count is Greater Than 5</template>
|
|
157
|
+
</j-if>
|
|
158
|
+
</div>
|
|
159
|
+
`);
|
|
160
|
+
assert.equal(element.textContent?.trim(), "String Count is Greater Than 5");
|
|
161
|
+
});
|
|
162
|
+
it("should handle undefined values in comparisons", () => {
|
|
163
|
+
const element = fixtureSync(html `
|
|
164
|
+
<div
|
|
165
|
+
@joist::value=${(e) => {
|
|
166
|
+
e.update({ oldValue: null, newValue: { count: undefined } });
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
<j-if bind="example.count > 5">
|
|
170
|
+
<template>Count is Greater Than 5</template>
|
|
171
|
+
</j-if>
|
|
172
|
+
</div>
|
|
173
|
+
`);
|
|
174
|
+
assert.equal(element.textContent?.trim(), "");
|
|
175
|
+
});
|
|
176
|
+
it("should handle not equal comparison", () => {
|
|
177
|
+
const element = fixtureSync(html `
|
|
178
|
+
<div
|
|
179
|
+
@joist::value=${(e) => {
|
|
180
|
+
e.update({ oldValue: null, newValue: { status: "inactive" } });
|
|
181
|
+
}}
|
|
182
|
+
>
|
|
183
|
+
<j-if bind="example.status != active">
|
|
184
|
+
<template>Status is Not Active</template>
|
|
185
|
+
</j-if>
|
|
186
|
+
</div>
|
|
187
|
+
`);
|
|
188
|
+
assert.equal(element.textContent?.trim(), "Status is Not Active");
|
|
189
|
+
});
|
|
190
|
+
it("should handle not equal comparison with matching value", () => {
|
|
191
|
+
const element = fixtureSync(html `
|
|
192
|
+
<div
|
|
193
|
+
@joist::value=${(e) => {
|
|
194
|
+
e.update({ oldValue: null, newValue: { status: "active" } });
|
|
195
|
+
}}
|
|
196
|
+
>
|
|
197
|
+
<j-if bind="example.status != active">
|
|
198
|
+
<template>Status is Not Active</template>
|
|
199
|
+
</j-if>
|
|
200
|
+
</div>
|
|
201
|
+
`);
|
|
202
|
+
assert.equal(element.textContent?.trim(), "");
|
|
203
|
+
});
|
|
204
|
+
it("should handle not equal comparison with string numbers", () => {
|
|
205
|
+
const element = fixtureSync(html `
|
|
206
|
+
<div
|
|
207
|
+
@joist::value=${(e) => {
|
|
208
|
+
e.update({ oldValue: null, newValue: { count: "10" } });
|
|
209
|
+
}}
|
|
210
|
+
>
|
|
211
|
+
<j-if bind="example.count != 5">
|
|
212
|
+
<template>Count is Not 5</template>
|
|
213
|
+
</j-if>
|
|
214
|
+
</div>
|
|
215
|
+
`);
|
|
216
|
+
assert.equal(element.textContent?.trim(), "Count is Not 5");
|
|
217
|
+
});
|
|
218
|
+
it("should handle not equal comparison with undefined", () => {
|
|
219
|
+
const element = fixtureSync(html `
|
|
220
|
+
<div
|
|
221
|
+
@joist::value=${(e) => {
|
|
222
|
+
e.update({ oldValue: null, newValue: { status: undefined } });
|
|
223
|
+
}}
|
|
224
|
+
>
|
|
225
|
+
<j-if bind="example.status != active">
|
|
226
|
+
<template>Status is Not Active</template>
|
|
227
|
+
</j-if>
|
|
228
|
+
</div>
|
|
229
|
+
`);
|
|
230
|
+
assert.equal(element.textContent?.trim(), "Status is Not Active");
|
|
231
|
+
});
|
|
232
|
+
it("should handle array length", () => {
|
|
233
|
+
const element = fixtureSync(html `
|
|
234
|
+
<div
|
|
235
|
+
@joist::value=${(e) => {
|
|
236
|
+
e.update({ oldValue: null, newValue: [0, 1, 2] });
|
|
237
|
+
}}
|
|
238
|
+
>
|
|
239
|
+
<j-if bind="example.length">
|
|
240
|
+
<template>Array has length</template>
|
|
241
|
+
<template else>Array has no length</template>
|
|
242
|
+
</j-if>
|
|
243
|
+
</div>
|
|
244
|
+
`);
|
|
245
|
+
assert.equal(element.textContent?.trim(), "Array has length");
|
|
246
|
+
});
|
|
247
|
+
it("should handle a first change even if the value is the same", () => {
|
|
248
|
+
const element = fixtureSync(html `
|
|
249
|
+
<div
|
|
250
|
+
@joist::value=${(e) => {
|
|
251
|
+
e.update({ oldValue: null, newValue: null, firstChange: true });
|
|
252
|
+
}}
|
|
253
|
+
>
|
|
254
|
+
<j-if bind="example.length">
|
|
255
|
+
<template>Array has length</template>
|
|
256
|
+
<template else>Array has no length</template>
|
|
257
|
+
</j-if>
|
|
258
|
+
</div>
|
|
259
|
+
`);
|
|
260
|
+
assert.equal(element.textContent?.trim(), "Array has no length");
|
|
261
|
+
});
|
|
262
|
+
it("should render in target container", () => {
|
|
263
|
+
const element = fixtureSync(html `
|
|
264
|
+
<div
|
|
265
|
+
@joist::value=${(e) => {
|
|
266
|
+
e.update({ oldValue: null, newValue: true });
|
|
267
|
+
}}
|
|
268
|
+
>
|
|
269
|
+
<j-if bind="test" target="#container">
|
|
270
|
+
<template>Visible Content</template>
|
|
271
|
+
</j-if>
|
|
272
|
+
|
|
273
|
+
<div id="container"></div>
|
|
274
|
+
</div>
|
|
275
|
+
`);
|
|
276
|
+
const container = element.querySelector("#container");
|
|
277
|
+
assert.equal(container?.textContent?.trim(), "Visible Content");
|
|
278
|
+
});
|
|
279
|
+
it("should wait for depends-on before dispatching events", async () => {
|
|
280
|
+
let eventDispatched = false;
|
|
281
|
+
customElements.define("dependency-1", class extends HTMLElement {
|
|
282
|
+
});
|
|
283
|
+
customElements.define("dependency-2", class extends HTMLElement {
|
|
284
|
+
});
|
|
285
|
+
fixtureSync(html `
|
|
286
|
+
<div
|
|
287
|
+
@joist::value=${(e) => {
|
|
288
|
+
if (e.expression.bindTo === "test") {
|
|
289
|
+
eventDispatched = true;
|
|
290
|
+
e.update({ oldValue: null, newValue: true });
|
|
291
|
+
}
|
|
292
|
+
}}
|
|
293
|
+
>
|
|
294
|
+
<j-if bind="test" depends-on="dependency-1,dependency-2">
|
|
295
|
+
<template>Visible Content</template>
|
|
296
|
+
</j-if>
|
|
297
|
+
</div>
|
|
298
|
+
`);
|
|
299
|
+
// Initially, no event should be dispatched
|
|
300
|
+
assert.isFalse(eventDispatched);
|
|
301
|
+
// Wait for the custom elements to be defined
|
|
302
|
+
await Promise.all([
|
|
303
|
+
customElements.whenDefined("dependency-1"),
|
|
304
|
+
customElements.whenDefined("dependency-2"),
|
|
305
|
+
]);
|
|
306
|
+
// Now the event should be dispatched
|
|
307
|
+
assert.isTrue(eventDispatched);
|
|
308
|
+
});
|
|
309
|
+
//# sourceMappingURL=if.element.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"if.element.test.js","sourceRoot":"","sources":["../../../src/lib/elements/if.element.test.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAI9B,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;IAC7D,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAA;;sBAEZ,CAAC,CAAkB,EAAE,EAAE;QACrC,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,C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ings":"AAIA,qBAIa,iBAAkB,SAAQ,WAAW;IAEhD,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAQ;CAC5B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import { element, css, html } from "@joist/element";
|
|
36
|
+
import { bind } from "../bind.js";
|
|
37
|
+
let JoistScopeElement = (() => {
|
|
38
|
+
let _classDecorators = [element({
|
|
39
|
+
// prettier-ignore
|
|
40
|
+
shadowDom: [css `:host{display: contents;}`, html `<slot></slot>`],
|
|
41
|
+
})];
|
|
42
|
+
let _classDescriptor;
|
|
43
|
+
let _classExtraInitializers = [];
|
|
44
|
+
let _classThis;
|
|
45
|
+
let _classSuper = HTMLElement;
|
|
46
|
+
let _scope_decorators;
|
|
47
|
+
let _scope_initializers = [];
|
|
48
|
+
let _scope_extraInitializers = [];
|
|
49
|
+
var JoistScopeElement = class extends _classSuper {
|
|
50
|
+
static { _classThis = this; }
|
|
51
|
+
static {
|
|
52
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
53
|
+
_scope_decorators = [bind()];
|
|
54
|
+
__esDecorate(this, null, _scope_decorators, { kind: "accessor", name: "scope", static: false, private: false, access: { has: obj => "scope" in obj, get: obj => obj.scope, set: (obj, value) => { obj.scope = value; } }, metadata: _metadata }, _scope_initializers, _scope_extraInitializers);
|
|
55
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
56
|
+
JoistScopeElement = _classThis = _classDescriptor.value;
|
|
57
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
58
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
59
|
+
}
|
|
60
|
+
#scope_accessor_storage = __runInitializers(this, _scope_initializers, null);
|
|
61
|
+
get scope() { return this.#scope_accessor_storage; }
|
|
62
|
+
set scope(value) { this.#scope_accessor_storage = value; }
|
|
63
|
+
constructor() {
|
|
64
|
+
super(...arguments);
|
|
65
|
+
__runInitializers(this, _scope_extraInitializers);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return JoistScopeElement = _classThis;
|
|
69
|
+
})();
|
|
70
|
+
export { JoistScopeElement };
|
|
71
|
+
//# sourceMappingURL=scope.element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.element.js","sourceRoot":"","sources":["../../../src/lib/elements/scope.element.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;IAMrB,iBAAiB;4BAJ7B,OAAO,CAAC;YACP,kBAAkB;YAClB,SAAS,EAAE,CAAC,GAAG,CAAA,2BAA2B,EAAE,IAAI,CAAA,eAAe,CAAC;SACjE,CAAC;;;;sBACqC,WAAW;;;;iCAAnB,SAAQ,WAAW;;;;iCAC/C,IAAI,EAAE;YACP,oKAAS,KAAK,6BAAL,KAAK,qFAAa;YAF7B,6KAGC;;;YAHY,uDAAiB;;QAE5B,uEAAsB,IAAI,EAAC;QAA3B,IAAS,KAAK,2CAAa;QAA3B,IAAS,KAAK,iDAAa;;;;;;;;SAFhB,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.element.test.d.ts","sourceRoot":"","sources":["../../../src/lib/elements/scope.element.test.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "../define.js";
|
|
2
|
+
import { fixtureSync, html } from "@open-wc/testing";
|
|
3
|
+
import { assert } from "chai";
|
|
4
|
+
import { JoistScopeElement } from "./scope.element.js";
|
|
5
|
+
describe("j-scope", () => {
|
|
6
|
+
it("should render its children", () => {
|
|
7
|
+
const element = fixtureSync(html `
|
|
8
|
+
<j-scope>
|
|
9
|
+
<div>Test Content</div>
|
|
10
|
+
</j-scope>
|
|
11
|
+
`);
|
|
12
|
+
assert.equal(element.textContent?.trim(), "Test Content");
|
|
13
|
+
});
|
|
14
|
+
it("should set and get scope property", async () => {
|
|
15
|
+
const element = fixtureSync(html `
|
|
16
|
+
<j-scope>
|
|
17
|
+
<j-val bind="scope.foo"></j-val>
|
|
18
|
+
</j-scope>
|
|
19
|
+
`);
|
|
20
|
+
element.scope = { foo: "bar" };
|
|
21
|
+
await Promise.resolve();
|
|
22
|
+
assert.equal(element.textContent?.trim(), "bar");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=scope.element.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.element.test.js","sourceRoot":"","sources":["../../../src/lib/elements/scope.element.test.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,OAAO,GAAG,WAAW,CAAoB,IAAI,CAAA;;;;KAIlD,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QACjD,MAAM,OAAO,GAAG,WAAW,CAAoB,IAAI,CAAA;;;;KAIlD,CAAC,CAAC;QAEH,OAAO,CAAC,KAAK,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;QAE/B,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAExB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.element.d.ts","sourceRoot":"","sources":["../../../src/lib/elements/value.element.ts"],"names":[],"mappings":"AAKA,qBAIa,iBAAkB,SAAQ,WAAW;IAEhD,QAAQ,CAAC,IAAI,SAAM;IAKnB,QAAQ,CAAC,SAAS,SAAM;IAElB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAuBzC"}
|