@esportsplus/reactivity 0.29.1 → 0.29.2

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/accordion.js ADDED
@@ -0,0 +1,45 @@
1
+ import * as reactivity_1ihsmodgjbfar0 from '@esportsplus/reactivity';
2
+ import { omit } from '@esportsplus/utilities';
3
+ import template from '../../components/template/index.js';
4
+ import './scss/index.scss';
5
+ class ReactiveObject_xy8kflxy8kfl2 extends reactivity_1ihsmodgjbfar0.ReactiveObject {
6
+ #active = this[reactivity_1ihsmodgjbfar0.SIGNAL](0);
7
+ constructor() {
8
+ super(null);
9
+ }
10
+ get active() {
11
+ return reactivity_1ihsmodgjbfar0.read(this.#active);
12
+ }
13
+ set active(_v0) {
14
+ reactivity_1ihsmodgjbfar0.write(this.#active, _v0);
15
+ }
16
+ }
17
+ const OMIT = ['state'];
18
+ let key = Symbol();
19
+ export default template.factory(function (attributes, content) {
20
+ let ref, state = attributes.state || reactivity_1ihsmodgjbfar0.reactive({
21
+ active: 0
22
+ }), n, html;
23
+ `
24
+ <div
25
+ ${omit(attributes, OMIT)}
26
+ ${{
27
+ class: () => {
28
+ return state.active && '--active';
29
+ },
30
+ onrender: (element) => {
31
+ (ref = element)[key] = state;
32
+ },
33
+ style: () => {
34
+ let parent = ref.closest('accordion');
35
+ if (parent && key in parent) {
36
+ parent[key].active = (+parent[key].active) + 1;
37
+ }
38
+ return state.active && `--max-height: ${ref.scrollHeight}`;
39
+ }
40
+ }}
41
+ >
42
+ ${content}
43
+ </div>
44
+ `;
45
+ });
package/accordion.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { reactive } from '@esportsplus/reactivity';
2
+ import { html, Attributes } from '@esportsplus/template';
3
+ import { omit } from '@esportsplus/utilities';
4
+ import template from '~/components/template';
5
+ import './scss/index.scss';
6
+
7
+
8
+ type A = Attributes & { state?: { active: boolean | number } };
9
+
10
+ type Accordion = HTMLElement & { [key: symbol]: { active: boolean | number } };
11
+
12
+
13
+ const OMIT = ['state'];
14
+
15
+
16
+ let key = Symbol();
17
+
18
+
19
+ export default template.factory(
20
+ function(attributes: A, content) {
21
+ let ref: Accordion,
22
+ state = attributes.state || reactive({
23
+ active: 0
24
+ });
25
+
26
+ return html`
27
+ <div
28
+ ${omit(attributes, OMIT)}
29
+ ${{
30
+ class: () => {
31
+ return state.active && '--active';
32
+ },
33
+ onrender: (element) => {
34
+ ( ref = element as Accordion )[key] = state;
35
+ },
36
+ style: () => {
37
+ let parent = ref.closest<Accordion>('accordion');
38
+
39
+ if (parent && key in parent) {
40
+ parent[key].active = (+parent[key].active) + 1;
41
+ }
42
+
43
+ return state.active && `--max-height: ${ref.scrollHeight}`;
44
+ }
45
+ }}
46
+ >
47
+ ${content}
48
+ </div>
49
+ `;
50
+ }
51
+ );
@@ -46,7 +46,9 @@ const plugin = {
46
46
  replacements.push(...primitives(ctx.sourceFile, bindings, isReactive));
47
47
  let objectResult = object(ctx.sourceFile, bindings);
48
48
  prepend.push(...objectResult.prepend);
49
- replacements.push(...objectResult.replacements, ...array(ctx.sourceFile, bindings), ...findRemainingCalls(ctx.checker, ctx.sourceFile, new Set(replacements.map(r => r.node))));
49
+ replacements.push(...objectResult.replacements);
50
+ replacements.push(...array(ctx.sourceFile, bindings));
51
+ replacements.push(...findRemainingCalls(ctx.checker, ctx.sourceFile, new Set(replacements.map(r => r.node))));
50
52
  if (replacements.length > 0 || prepend.length > 0) {
51
53
  importsIntent.push({
52
54
  namespace: COMPILER_NAMESPACE,
@@ -17,7 +17,7 @@ const COMPOUND_OPERATORS = new Map([
17
17
  [ts.SyntaxKind.QuestionQuestionEqualsToken, '??'],
18
18
  [ts.SyntaxKind.SlashEqualsToken, '/']
19
19
  ]);
20
- function isInScope(reference, binding) {
20
+ function inScope(reference, binding) {
21
21
  let current = reference;
22
22
  while (current) {
23
23
  if (current === binding.scope) {
@@ -89,7 +89,7 @@ function visit(ctx, node) {
89
89
  let bindings = ctx.scopedBindings, binding, name = node.text;
90
90
  for (let i = 0, n = bindings.length; i < n; i++) {
91
91
  let b = bindings[i];
92
- if (b.name === name && isInScope(node, b)) {
92
+ if (b.name === name && inScope(node, b)) {
93
93
  binding = b;
94
94
  }
95
95
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "@esportsplus/utilities": "^0.27.2"
5
5
  },
6
6
  "devDependencies": {
7
- "@esportsplus/typescript": "^0.26.0",
7
+ "@esportsplus/typescript": "^0.26.2",
8
8
  "@types/node": "^25.0.3",
9
9
  "vite": "^7.3.1"
10
10
  },
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "type": "module",
33
33
  "types": "build/index.d.ts",
34
- "version": "0.29.1",
34
+ "version": "0.29.2",
35
35
  "scripts": {
36
36
  "build": "tsc",
37
37
  "build:test": "pnpm build && vite build --config test/vite.config.ts",
@@ -89,12 +89,13 @@ const plugin: Plugin = {
89
89
  let objectResult = object(ctx.sourceFile, bindings);
90
90
 
91
91
  prepend.push(...objectResult.prepend);
92
- replacements.push(
93
- ...objectResult.replacements,
94
- ...array(ctx.sourceFile, bindings),
95
- // Find remaining reactive() calls that weren't transformed and replace with namespace version
96
- ...findRemainingCalls(ctx.checker, ctx.sourceFile, new Set(replacements.map(r => r.node)))
97
- );
92
+ replacements.push(...objectResult.replacements);
93
+
94
+ // Run array transform separately ( avoid race conditions )
95
+ replacements.push(...array(ctx.sourceFile, bindings));
96
+
97
+ // Find remaining reactive() calls that weren't transformed and replace with namespace version
98
+ replacements.push(...findRemainingCalls(ctx.checker, ctx.sourceFile, new Set(replacements.map(r => r.node))));
98
99
 
99
100
  // Build import intent
100
101
  if (replacements.length > 0 || prepend.length > 0) {
@@ -39,7 +39,7 @@ const COMPOUND_OPERATORS = new Map<ts.SyntaxKind, string>([
39
39
  ]);
40
40
 
41
41
 
42
- function isInScope(reference: ts.Node, binding: ScopeBinding): boolean {
42
+ function inScope(reference: ts.Node, binding: ScopeBinding): boolean {
43
43
  let current: ts.Node | undefined = reference;
44
44
 
45
45
  while (current) {
@@ -142,7 +142,7 @@ function visit(ctx: TransformContext, node: ts.Node): void {
142
142
  for (let i = 0, n = bindings.length; i < n; i++) {
143
143
  let b = bindings[i];
144
144
 
145
- if (b.name === name && isInScope(node, b)) {
145
+ if (b.name === name && inScope(node, b)) {
146
146
  binding = b;
147
147
  }
148
148
  }