Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aria-ui/core

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aria-ui/core - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

55

dist/index.d.ts
import { HTMLElement as HTMLElement$1 } from 'server-dom-shim';
import { Signal as Signal$1, ReadonlySignal as ReadonlySignal$1, batch as batch$1, untracked as untracked$1, signal, computed } from '@preact/signals-core';
import { batch as batch$1, untracked as untracked$1 } from '@preact/signals-core';
import { AriaAttributes } from '@dddstack/ariatype-aria-attributes';

@@ -49,18 +49,31 @@ import { AriaRole } from '@dddstack/ariatype-aria-roles';

/**
* A mutable signal that can be used to manage reactive state changes.
*
* This is a re-export of `Signal` type from `@preact/signals-core`.
*
* @group Signals
* A read-only signal that holds a reactive value.
*/
type Signal<T> = Signal$1<T>;
interface ReadonlySignal<T> {
/**
* Get the signal's current value.
*/
get(): T;
/**
* Get the signal's current value without subscribing.
*/
peek(): T;
/**
* @deprecated
*/
get value(): T;
}
/**
* A read-only signal, providing a way to observe state changes without the
* ability to modify the state.
*
* This is a re-export of `ReadonlySignal` type from `@preact/signals-core`.
*
* @group Signals
* A mutable signal that can be used to manage reactive state changes.
*/
type ReadonlySignal<T> = ReadonlySignal$1<T>;
interface Signal<T> extends ReadonlySignal<T> {
/**
* Set the value of the signal.
*/
set(value: T): void;
/**
* @deprecated
*/
set value(value: T);
}
/**

@@ -88,7 +101,5 @@ * Groups multiple signal updates into a single batch, optimizing performance by reducing the number of updates.

*
* This is an alias for `signal` from `@preact/signals-core`.
*
* @group Signals
*/
declare const createSignal: typeof signal;
declare function createSignal<T>(value: T): Signal<T>;
/**

@@ -100,7 +111,5 @@ * Creates a computed signal that automatically updates its value based on the

*
* This is an alias for `computed` from `@preact/signals-core`.
*
* @group Signals
*/
declare const createComputed: typeof computed;
declare function createComputed<T>(fn: () => T): ReadonlySignal<T>;
/**

@@ -137,7 +146,7 @@ * Registers a callback to be called when the given element is connected to the

*/
provide(element: ConnectableElement, signal: Signal<T>): void;
provide(element: ConnectableElement, signal: Signal<T> | ReadonlySignal<T>): void;
/**
* Receives the signal from a parent element.
* @param element The element to consume the signal from.
* @returns A signal that is double bound to the provided signal.
* @returns A signal that is double-bound to the provided signal.
*/

@@ -233,3 +242,3 @@ consume(element: ConnectableElement): Signal<T>;

type SignalState<T extends object> = {
[K in keyof T]: Signal$1<T[K]>;
[K in keyof T]: Signal<T[K]>;
};

@@ -236,0 +245,0 @@ /**

@@ -54,28 +54,2 @@ // src/base-element.ts

// src/signals.ts
import {
batch as _batch,
untracked as _untracked,
computed,
effect,
signal
} from "@preact/signals-core";
var batch = _batch;
var untracked = _untracked;
var createSignal = signal;
var createComputed = computed;
function useEffect(element, callback) {
let cleanup = void 0;
const dispose = () => {
cleanup == null ? void 0 : cleanup();
cleanup = void 0;
};
element.addConnectedCallback(() => {
cleanup == null ? void 0 : cleanup();
cleanup = effect(callback);
return dispose;
});
return dispose;
}
// src/context.ts

@@ -96,3 +70,3 @@ var ContextRequestEvent = class extends Event {

}
provide(element, signal3) {
provide(element, signal2) {
element.addEventListener("aria-ui/context-request", (event) => {

@@ -104,3 +78,3 @@ if (element === event.target) {

if (key === this.key) {
callback(signal3);
callback(signal2);
event.stopPropagation();

@@ -111,36 +85,42 @@ }

consume(element) {
const consumer = createSignal(this.defaultValue);
let dispose = void 0;
let getter = null;
let peeker = null;
let setter = null;
element.addConnectedCallback(() => {
element.dispatchEvent(
new ContextRequestEvent(this.key, (provider) => {
dispose == null ? void 0 : dispose();
dispose = bind(provider, consumer);
getter = () => provider.get();
peeker = () => provider.peek();
setter = (value) => provider.set(value);
})
);
return () => {
dispose == null ? void 0 : dispose();
dispose = void 0;
};
});
return consumer;
const get = () => {
return getter ? getter() : this.defaultValue;
};
const set = (value) => {
setter == null ? void 0 : setter(value);
};
const peek = () => {
return peeker ? peeker() : this.defaultValue;
};
return {
get,
/**
* @deprecated
*/
get value() {
return get();
},
set,
/**
* @deprecated
*/
set value(value) {
set(value);
},
peek
};
}
};
function bind(provider, consumer) {
consumer.value = provider.peek();
const unsubscribeProvider = provider.subscribe((value) => {
if (consumer.peek() !== value) {
consumer.value = value;
}
});
const unsubscribeConsumer = consumer.subscribe((value) => {
if (provider.peek() !== value) {
provider.value = value;
}
});
return () => {
unsubscribeProvider();
unsubscribeConsumer();
};
}
function createContext(key, defaultValue) {

@@ -153,2 +133,75 @@ return new ContextImpl(

// src/signals.ts
import {
batch as _batch,
untracked as _untracked,
computed,
effect,
signal
} from "@preact/signals-core";
var MutableSignal = class {
constructor(value) {
this.impl = signal(value);
}
/**
* @deprecated
*/
get value() {
return this.impl.value;
}
/**
* @deprecated
*/
set value(value) {
this.impl.value = value;
}
get() {
return this.impl.value;
}
set(value) {
this.impl.value = value;
}
peek() {
return this.impl.peek();
}
};
var ComputedSignal = class {
constructor(fn) {
this.impl = computed(fn);
}
/**
* @deprecated
*/
get value() {
return this.impl.value;
}
get() {
return this.impl.value;
}
peek() {
return this.impl.peek();
}
};
var batch = _batch;
var untracked = _untracked;
function createSignal(value) {
return new MutableSignal(value);
}
function createComputed(fn) {
return new ComputedSignal(fn);
}
function useEffect(element, callback) {
let cleanup = void 0;
const dispose = () => {
cleanup == null ? void 0 : cleanup();
cleanup = void 0;
};
element.addConnectedCallback(() => {
cleanup == null ? void 0 : cleanup();
cleanup = effect(callback);
return dispose;
});
return dispose;
}
// src/dom.ts

@@ -190,3 +243,3 @@ function useEventListener(element, type, listener, options) {

if (mutationList.length > 0) {
mutationCounter.value += 1;
mutationCounter.set(mutationCounter.get() + 1);
}

@@ -208,3 +261,3 @@ });

return createComputed(() => {
mutationCounter.value;
mutationCounter.get();
return element.querySelector(selector);

@@ -220,3 +273,3 @@ });

return createComputed(() => {
mutationCounter.value;
mutationCounter.get();
return element.querySelectorAll(selector);

@@ -264,7 +317,6 @@ });

// src/signal-state.ts
import { signal as signal2 } from "@preact/signals-core";
function mapValues(signals) {
const values = {};
for (const [key, signal3] of getObjectEntries(signals)) {
values[key] = signal3.value;
for (const [key, signal2] of getObjectEntries(signals)) {
values[key] = signal2.get();
}

@@ -276,3 +328,3 @@ return values;

for (const [key, value] of getObjectEntries(values)) {
signals[key] = signal2(value);
signals[key] = createSignal(value);
}

@@ -279,0 +331,0 @@ return signals;

{
"name": "@aria-ui/core",
"type": "module",
"version": "0.0.14",
"version": "0.0.15",
"private": false,

@@ -14,7 +14,7 @@ "sideEffects": false,

"@dddstack/ariatype-aria-roles": "^2.0.0",
"@preact/signals-core": "^1.6.0",
"@preact/signals-core": "^1.6.1",
"server-dom-shim": "^1.0.2"
},
"devDependencies": {
"tsup": "^8.0.2",
"tsup": "^8.1.0",
"typescript": "^5.4.5"

@@ -21,0 +21,0 @@ },

@@ -19,2 +19,64 @@ # @aria-ui/core

## Interfaces
### ReadonlySignal\<T\>
A read-only signal that holds a reactive value.
#### Accessors
##### value
#### Methods
##### get()
```ts
get(): T
```
Get the signal's current value.
##### peek()
```ts
peek(): T
```
Get the signal's current value without subscribing.
### Signal\<T\>
A mutable signal that can be used to manage reactive state changes.
#### Accessors
##### value
#### Methods
##### get()
```ts
get(): T
```
Get the signal's current value.
##### peek()
```ts
peek(): T
```
Get the signal's current value without subscribing.
##### set()
```ts
set(value: T): void
```
Set the value of the signal.
## Functions

@@ -55,3 +117,3 @@

```ts
provide(element: ConnectableElement, signal: Signal<T>): void
provide(element: ConnectableElement, signal: Signal<T> | ReadonlySignal<T>): void
```

@@ -186,3 +248,3 @@

| :-- | :-- | :-- |
| `addConnectedCallback` | (`callback`: () => `void` \| `VoidFunction`) => `void` | Registers a callback to be called when the element is connected to the DOM.<br />This callback can return a cleanup function that will be called when the<br />element is disconnected from the DOM. |
| `addConnectedCallback` | (`callback`: () => `void` \| `VoidFunction`) => `void` | Registers a callback to be called when the element is connected to the DOM. This callback can return a cleanup function that will be called when the element is disconnected from the DOM. |

@@ -228,22 +290,2 @@ ## Props and States

### ReadonlySignal\<T\>
```ts
type ReadonlySignal<T>: _ReadonlySignal<T>;
```
A read-only signal, providing a way to observe state changes without the ability to modify the state.
This is a re-export of `ReadonlySignal` type from `@preact/signals-core`.
### Signal\<T\>
```ts
type Signal<T>: _Signal<T>;
```
A mutable signal that can be used to manage reactive state changes.
This is a re-export of `Signal` type from `@preact/signals-core`.
### SignalValue\<S\>

@@ -275,4 +317,2 @@

This is an alias for `computed` from `@preact/signals-core`.
### createSignal()

@@ -286,4 +326,2 @@

This is an alias for `signal` from `@preact/signals-core`.
### untracked()

@@ -290,0 +328,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc