@dnd-kit/state 0.0.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/README.md +5 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +139 -0
- package/dist/index.mjs +113 -0
- package/package.json +31 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReadonlySignal } from '@preact/signals-core';
|
|
2
|
+
export { ReadonlySignal, Signal, batch, effect, signal, untracked } from '@preact/signals-core';
|
|
3
|
+
|
|
4
|
+
declare function computed<T>(compute: () => T, comparator?: (a: T, b: T) => boolean): ReadonlySignal<T>;
|
|
5
|
+
|
|
6
|
+
declare function deepEqual<T>(a: T, b: T): boolean;
|
|
7
|
+
|
|
8
|
+
declare function reactive(target: Object, propertyKey: string): void;
|
|
9
|
+
declare function derived(target: Object, propertyKey: string, descriptor: PropertyDescriptor): void;
|
|
10
|
+
|
|
11
|
+
type CleanupFunction = () => void;
|
|
12
|
+
type Effect = () => CleanupFunction | void;
|
|
13
|
+
|
|
14
|
+
declare function effects(...entries: Effect[]): CleanupFunction;
|
|
15
|
+
|
|
16
|
+
export { CleanupFunction, Effect, computed, deepEqual, derived, effects, reactive };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Signal: () => import_signals_core4.Signal,
|
|
24
|
+
batch: () => import_signals_core4.batch,
|
|
25
|
+
computed: () => computed,
|
|
26
|
+
deepEqual: () => deepEqual,
|
|
27
|
+
derived: () => derived,
|
|
28
|
+
effect: () => import_signals_core4.effect,
|
|
29
|
+
effects: () => effects,
|
|
30
|
+
reactive: () => reactive,
|
|
31
|
+
signal: () => import_signals_core4.signal,
|
|
32
|
+
untracked: () => import_signals_core4.untracked
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_signals_core4 = require("@preact/signals-core");
|
|
36
|
+
|
|
37
|
+
// src/computed.ts
|
|
38
|
+
var import_signals_core = require("@preact/signals-core");
|
|
39
|
+
function computed(compute, comparator) {
|
|
40
|
+
if (comparator) {
|
|
41
|
+
let previousValue;
|
|
42
|
+
return (0, import_signals_core.computed)(() => {
|
|
43
|
+
const value = compute();
|
|
44
|
+
if (value && previousValue && comparator(previousValue, value)) {
|
|
45
|
+
return previousValue;
|
|
46
|
+
}
|
|
47
|
+
previousValue = value;
|
|
48
|
+
return value;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return (0, import_signals_core.computed)(compute);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/comparators.ts
|
|
55
|
+
function deepEqual(a, b) {
|
|
56
|
+
if (a === b) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(a)) {
|
|
60
|
+
if (!Array.isArray(b)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (a.length !== b.length) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const hasDifferentValues = a.some(
|
|
67
|
+
(value, index) => !deepEqual(value, b[index])
|
|
68
|
+
);
|
|
69
|
+
return !hasDifferentValues;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/decorators.ts
|
|
79
|
+
var import_signals_core2 = require("@preact/signals-core");
|
|
80
|
+
function reactive(target, propertyKey) {
|
|
81
|
+
const store = /* @__PURE__ */ new WeakMap();
|
|
82
|
+
Object.defineProperty(target, propertyKey, {
|
|
83
|
+
get() {
|
|
84
|
+
if (!store.get(this)) {
|
|
85
|
+
store.set(this, (0, import_signals_core2.signal)(void 0));
|
|
86
|
+
}
|
|
87
|
+
const stored = store.get(this);
|
|
88
|
+
const value = stored == null ? void 0 : stored.value;
|
|
89
|
+
return value;
|
|
90
|
+
},
|
|
91
|
+
set(value) {
|
|
92
|
+
const stored = store.get(this);
|
|
93
|
+
if (stored) {
|
|
94
|
+
if (stored.peek() !== value) {
|
|
95
|
+
stored.value = value;
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
store.set(this, (0, import_signals_core2.signal)(value));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function derived(target, propertyKey, descriptor) {
|
|
104
|
+
const store = /* @__PURE__ */ new WeakMap();
|
|
105
|
+
const compute = descriptor.get;
|
|
106
|
+
Object.defineProperty(target, propertyKey, {
|
|
107
|
+
get() {
|
|
108
|
+
if (!compute) {
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
if (!store.get(this)) {
|
|
112
|
+
store.set(this, computed(compute.bind(this)));
|
|
113
|
+
}
|
|
114
|
+
const stored = store.get(this);
|
|
115
|
+
const value = stored == null ? void 0 : stored.value;
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/effects.ts
|
|
122
|
+
var import_signals_core3 = require("@preact/signals-core");
|
|
123
|
+
function effects(...entries) {
|
|
124
|
+
const effects2 = entries.map(import_signals_core3.effect);
|
|
125
|
+
return () => effects2.forEach((cleanup) => cleanup());
|
|
126
|
+
}
|
|
127
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
+
0 && (module.exports = {
|
|
129
|
+
Signal,
|
|
130
|
+
batch,
|
|
131
|
+
computed,
|
|
132
|
+
deepEqual,
|
|
133
|
+
derived,
|
|
134
|
+
effect,
|
|
135
|
+
effects,
|
|
136
|
+
reactive,
|
|
137
|
+
signal,
|
|
138
|
+
untracked
|
|
139
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
batch,
|
|
4
|
+
effect as effect2,
|
|
5
|
+
untracked,
|
|
6
|
+
signal as signal2,
|
|
7
|
+
Signal
|
|
8
|
+
} from "@preact/signals-core";
|
|
9
|
+
|
|
10
|
+
// src/computed.ts
|
|
11
|
+
import {
|
|
12
|
+
computed as computedSignal
|
|
13
|
+
} from "@preact/signals-core";
|
|
14
|
+
function computed(compute, comparator) {
|
|
15
|
+
if (comparator) {
|
|
16
|
+
let previousValue;
|
|
17
|
+
return computedSignal(() => {
|
|
18
|
+
const value = compute();
|
|
19
|
+
if (value && previousValue && comparator(previousValue, value)) {
|
|
20
|
+
return previousValue;
|
|
21
|
+
}
|
|
22
|
+
previousValue = value;
|
|
23
|
+
return value;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return computedSignal(compute);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/comparators.ts
|
|
30
|
+
function deepEqual(a, b) {
|
|
31
|
+
if (a === b) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(a)) {
|
|
35
|
+
if (!Array.isArray(b)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (a.length !== b.length) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const hasDifferentValues = a.some(
|
|
42
|
+
(value, index) => !deepEqual(value, b[index])
|
|
43
|
+
);
|
|
44
|
+
return !hasDifferentValues;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/decorators.ts
|
|
54
|
+
import { signal } from "@preact/signals-core";
|
|
55
|
+
function reactive(target, propertyKey) {
|
|
56
|
+
const store = /* @__PURE__ */ new WeakMap();
|
|
57
|
+
Object.defineProperty(target, propertyKey, {
|
|
58
|
+
get() {
|
|
59
|
+
if (!store.get(this)) {
|
|
60
|
+
store.set(this, signal(void 0));
|
|
61
|
+
}
|
|
62
|
+
const stored = store.get(this);
|
|
63
|
+
const value = stored == null ? void 0 : stored.value;
|
|
64
|
+
return value;
|
|
65
|
+
},
|
|
66
|
+
set(value) {
|
|
67
|
+
const stored = store.get(this);
|
|
68
|
+
if (stored) {
|
|
69
|
+
if (stored.peek() !== value) {
|
|
70
|
+
stored.value = value;
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
store.set(this, signal(value));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function derived(target, propertyKey, descriptor) {
|
|
79
|
+
const store = /* @__PURE__ */ new WeakMap();
|
|
80
|
+
const compute = descriptor.get;
|
|
81
|
+
Object.defineProperty(target, propertyKey, {
|
|
82
|
+
get() {
|
|
83
|
+
if (!compute) {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
if (!store.get(this)) {
|
|
87
|
+
store.set(this, computed(compute.bind(this)));
|
|
88
|
+
}
|
|
89
|
+
const stored = store.get(this);
|
|
90
|
+
const value = stored == null ? void 0 : stored.value;
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/effects.ts
|
|
97
|
+
import { effect } from "@preact/signals-core";
|
|
98
|
+
function effects(...entries) {
|
|
99
|
+
const effects2 = entries.map(effect);
|
|
100
|
+
return () => effects2.forEach((cleanup) => cleanup());
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
Signal,
|
|
104
|
+
batch,
|
|
105
|
+
computed,
|
|
106
|
+
deepEqual,
|
|
107
|
+
derived,
|
|
108
|
+
effect2 as effect,
|
|
109
|
+
effects,
|
|
110
|
+
reactive,
|
|
111
|
+
signal2 as signal,
|
|
112
|
+
untracked
|
|
113
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dnd-kit/state",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --external react",
|
|
14
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react",
|
|
15
|
+
"lint": "TIMING=1 eslint src/**/*.ts* --fix",
|
|
16
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@preact/signals-core": "^1.6.0",
|
|
20
|
+
"tslib": "^2.6.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@dnd-kit/eslint-config": "*",
|
|
24
|
+
"eslint": "^8.38.0",
|
|
25
|
+
"tsup": "^6.7.0",
|
|
26
|
+
"typescript": "^5.0.4"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
31
|
+
}
|