@jsweb/ui 1.2.0 → 1.2.3
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/index.es.js +2 -0
- package/index.es.js.map +1 -0
- package/index.umd.js +2 -0
- package/index.umd.js.map +1 -0
- package/package.json +8 -23
- package/src/evaluator.d.ts +2 -0
- package/{dist/src → src}/parser.d.ts +1 -1
- package/.github/workflows/npm-publish.yml +0 -21
- package/.prettierignore +0 -3
- package/.prettierrc +0 -7
- package/HISTORY.md +0 -36
- package/PROJECT.md +0 -90
- package/dist/src/evaluator.d.ts +0 -2
- package/dist/ui.es.js +0 -2
- package/dist/ui.es.js.map +0 -1
- package/dist/ui.umd.js +0 -2
- package/dist/ui.umd.js.map +0 -1
- package/index.html +0 -162
- package/src/evaluator.ts +0 -33
- package/src/index.ts +0 -10
- package/src/parser.ts +0 -429
- package/src/reactivity.ts +0 -175
- package/tsconfig.json +0 -23
- package/vite.config.ts +0 -16
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/src → src}/index.d.ts +0 -0
- /package/{dist/src → src}/reactivity.d.ts +0 -0
- /package/{dist/vite.config.d.ts → vite.config.d.ts} +0 -0
package/src/reactivity.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
let activeEffect: symbol | null = null
|
|
2
|
-
const targetMap = new WeakMap<
|
|
3
|
-
object,
|
|
4
|
-
Map<string | symbol, Set<ReactiveEffect>>
|
|
5
|
-
>()
|
|
6
|
-
const proxyMap = new WeakMap<object, any>()
|
|
7
|
-
const effectMap = new WeakMap<symbol, ReactiveEffect>()
|
|
8
|
-
|
|
9
|
-
export class ReactiveEffect {
|
|
10
|
-
active = true
|
|
11
|
-
deps: Set<Set<ReactiveEffect>> = new Set()
|
|
12
|
-
|
|
13
|
-
constructor(public fn: () => void) {}
|
|
14
|
-
|
|
15
|
-
run() {
|
|
16
|
-
if (!this.active) return this.fn()
|
|
17
|
-
|
|
18
|
-
this.cleanup()
|
|
19
|
-
|
|
20
|
-
activeEffect = Symbol()
|
|
21
|
-
effectMap.set(activeEffect, this)
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
return this.fn()
|
|
25
|
-
} finally {
|
|
26
|
-
effectMap.delete(activeEffect)
|
|
27
|
-
activeEffect = null
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
stop() {
|
|
32
|
-
if (this.active) {
|
|
33
|
-
this.cleanup()
|
|
34
|
-
this.active = false
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
cleanup() {
|
|
39
|
-
this.deps.forEach((dep) => dep.delete(this))
|
|
40
|
-
this.deps.clear()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
effect() {
|
|
44
|
-
return {
|
|
45
|
-
run: () => this.run(),
|
|
46
|
-
stop: () => this.stop(),
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function effect(fn: () => void) {
|
|
52
|
-
const ref = new ReactiveEffect(fn)
|
|
53
|
-
ref.run()
|
|
54
|
-
return ref.effect()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function track(target: object, key: string | symbol) {
|
|
58
|
-
if (activeEffect) {
|
|
59
|
-
let depsMap = targetMap.get(target)
|
|
60
|
-
if (!depsMap) {
|
|
61
|
-
depsMap = new Map()
|
|
62
|
-
targetMap.set(target, depsMap)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let dep = depsMap.get(key)
|
|
66
|
-
if (!dep) {
|
|
67
|
-
dep = new Set()
|
|
68
|
-
depsMap.set(key, dep)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const active = effectMap.get(activeEffect)
|
|
72
|
-
if (active) {
|
|
73
|
-
dep.add(active)
|
|
74
|
-
active.deps.add(dep)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function trigger(target: object, key: string | symbol) {
|
|
80
|
-
const depsMap = targetMap.get(target)
|
|
81
|
-
if (!depsMap) return
|
|
82
|
-
|
|
83
|
-
const dep = depsMap.get(key)
|
|
84
|
-
if (dep) {
|
|
85
|
-
const effects = new Set(dep)
|
|
86
|
-
effects.forEach((effect) => effect.run())
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function reactive<T extends object>(target: T): T {
|
|
91
|
-
const notObject = typeof target !== 'object' || target === null
|
|
92
|
-
if (notObject) return target
|
|
93
|
-
|
|
94
|
-
const isReactive = Object.hasOwn(target, '_isReactive')
|
|
95
|
-
if (isReactive) return target
|
|
96
|
-
|
|
97
|
-
const existingProxy = proxyMap.get(target)
|
|
98
|
-
if (existingProxy) return existingProxy
|
|
99
|
-
|
|
100
|
-
const proxy = new Proxy(target, {
|
|
101
|
-
get(obj, key, receiver) {
|
|
102
|
-
if (key === '_isReactive') return true
|
|
103
|
-
track(obj, key)
|
|
104
|
-
const res = Reflect.get(obj, key, receiver)
|
|
105
|
-
// deep reactivity
|
|
106
|
-
if (typeof res === 'object' && res !== null) {
|
|
107
|
-
return reactive(res)
|
|
108
|
-
}
|
|
109
|
-
return res
|
|
110
|
-
},
|
|
111
|
-
set(obj, key, value, receiver) {
|
|
112
|
-
const isArray = Array.isArray(obj)
|
|
113
|
-
const oldValue = Reflect.get(obj, key, receiver)
|
|
114
|
-
const hadKey =
|
|
115
|
-
isArray && String(Number(key)) === key
|
|
116
|
-
? Number(key) < obj.length
|
|
117
|
-
: Object.hasOwn(obj, key)
|
|
118
|
-
|
|
119
|
-
const result = Reflect.set(obj, key, value, receiver)
|
|
120
|
-
|
|
121
|
-
if (!hadKey) {
|
|
122
|
-
trigger(obj, key)
|
|
123
|
-
if (isArray && key !== 'length') {
|
|
124
|
-
trigger(obj, 'length')
|
|
125
|
-
}
|
|
126
|
-
} else if (oldValue !== value) {
|
|
127
|
-
trigger(obj, key)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return result
|
|
131
|
-
},
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
proxyMap.set(target, proxy)
|
|
135
|
-
return proxy
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function traverse(value: any, seen = new Set()) {
|
|
139
|
-
if (typeof value !== 'object' || value === null || seen.has(value)) {
|
|
140
|
-
return value
|
|
141
|
-
}
|
|
142
|
-
seen.add(value)
|
|
143
|
-
for (const key in value) {
|
|
144
|
-
traverse(value[key], seen)
|
|
145
|
-
}
|
|
146
|
-
return value
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function watch(
|
|
150
|
-
source: any | (() => any),
|
|
151
|
-
cb: (newValue: any, oldValue: any) => void,
|
|
152
|
-
options?: { immediate?: boolean },
|
|
153
|
-
) {
|
|
154
|
-
let oldValue: any
|
|
155
|
-
let isFirstRun = true
|
|
156
|
-
|
|
157
|
-
const getter = source instanceof Function ? source : () => traverse(source)
|
|
158
|
-
|
|
159
|
-
const runner = effect(() => {
|
|
160
|
-
const newValue = getter()
|
|
161
|
-
|
|
162
|
-
if (isFirstRun) {
|
|
163
|
-
isFirstRun = false
|
|
164
|
-
oldValue = newValue
|
|
165
|
-
if (options?.immediate) {
|
|
166
|
-
cb(newValue, undefined)
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
cb(newValue, oldValue)
|
|
170
|
-
oldValue = newValue
|
|
171
|
-
}
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
return runner.stop
|
|
175
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
|
|
9
|
-
/* Bundler mode */
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
|
|
16
|
-
/* Linting */
|
|
17
|
-
"strict": true,
|
|
18
|
-
"noUnusedLocals": true,
|
|
19
|
-
"noUnusedParameters": true,
|
|
20
|
-
"noFallthroughCasesInSwitch": true
|
|
21
|
-
},
|
|
22
|
-
"include": ["src", "vite.config.ts"]
|
|
23
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite'
|
|
2
|
-
import dts from 'vite-plugin-dts'
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
build: {
|
|
6
|
-
lib: {
|
|
7
|
-
name: '@jsweb/ui',
|
|
8
|
-
formats: ['es', 'umd'],
|
|
9
|
-
entry: './src/index.ts',
|
|
10
|
-
fileName: (format: string) => `ui.${format}.js`,
|
|
11
|
-
},
|
|
12
|
-
sourcemap: true,
|
|
13
|
-
minify: 'terser',
|
|
14
|
-
},
|
|
15
|
-
plugins: [dts({ insertTypesEntry: true })],
|
|
16
|
-
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|