solely 0.4.20 → 0.5.0
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 +138 -38
- package/dist/compiler/ir/buildIR.cjs +1 -1
- package/dist/compiler/ir/buildIR.js +1 -1
- package/dist/compiler/parser/parser.cjs +1 -1
- package/dist/compiler/parser/parser.js +1 -1
- package/dist/components/elements/select/index.cjs +1 -1
- package/dist/components/elements/select/index.d.ts +1 -5
- package/dist/components/elements/select/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/plugins/solely-vite-plugin.cjs +1 -1
- package/dist/plugins/solely-vite-plugin.js +1 -1
- package/dist/runtime/component/base-element.cjs +1 -1
- package/dist/runtime/component/base-element.d.ts +6 -1
- package/dist/runtime/component/base-element.js +1 -1
- package/dist/runtime/component/decorators.cjs +1 -1
- package/dist/runtime/component/decorators.js +1 -1
- package/dist/runtime/index.cjs +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/reactivity/computed.cjs +1 -0
- package/dist/runtime/reactivity/computed.d.ts +36 -0
- package/dist/runtime/reactivity/computed.js +1 -0
- package/dist/runtime/reactivity/index.d.ts +6 -2
- package/dist/runtime/reactivity/observe.cjs +1 -1
- package/dist/runtime/reactivity/observe.d.ts +4 -32
- package/dist/runtime/reactivity/observe.js +1 -1
- package/dist/runtime/reactivity/watch.cjs +1 -0
- package/dist/runtime/reactivity/watch.d.ts +64 -0
- package/dist/runtime/reactivity/watch.js +1 -0
- package/dist/runtime/renderer/renderIR.cjs +1 -1
- package/dist/runtime/renderer/renderIR.d.ts +30 -20
- package/dist/runtime/renderer/renderIR.js +1 -1
- package/dist/shared/env.cjs +1 -1
- package/dist/shared/env.d.ts +2 -0
- package/dist/shared/env.js +1 -1
- package/dist/shared/index.cjs +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/is-object.d.ts +1 -1
- package/dist/types/ast.cjs +1 -1
- package/dist/types/ast.d.ts +1 -0
- package/dist/types/ast.js +1 -1
- package/dist/types/ir.d.ts +2 -0
- package/dist/types/lifecycle.cjs +1 -1
- package/dist/types/lifecycle.d.ts +1 -1
- package/dist/types/lifecycle.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,7 +151,9 @@ class MyCounter extends BaseElement<{ count: number }> {
|
|
|
151
151
|
| **双向绑定** | `s-model="字段路径"` | `s-model="字段路径"` | `<input s-model="$data.username">` |
|
|
152
152
|
| **原始事件** | `@事件名="语句"` | `on-事件名="语句"` | `<button @click="$data.count++">增加</button>` |
|
|
153
153
|
| **条件渲染** | `<If test="表达式">` | `<If condition="表达式">` | `<If test="$data.ok"><p>成功</p></If>` |
|
|
154
|
+
| **显隐控制** | `<Show test="表达式">` | `<Show condition="表达式">` | `<Show test="$data.visible">内容</Show>` |
|
|
154
155
|
| **列表渲染** | `<For each="数组" item="项变量">` | `<For each="数组" item="项变量">` | `<For each="$data.list" item="it">{{ it }}</For>` |
|
|
156
|
+
| **组件缓存** | `<If keepalive>` | - | `<If test="$data.ok" keepalive>...</If>` |
|
|
155
157
|
| **动态类** | `:class="对象/数组/字符串"` | `s-class="对象/数组/字符串"` | `<div :class="{ active: $data.isActive }">` |
|
|
156
158
|
| **动态样式** | `:style="对象"` | `s-style="对象"` | `<div :style="{ color: $data.c }">` |
|
|
157
159
|
|
|
@@ -267,7 +269,29 @@ class MyCounter extends BaseElement<{ count: number }> {
|
|
|
267
269
|
</Else>
|
|
268
270
|
```
|
|
269
271
|
|
|
270
|
-
#### 7.
|
|
272
|
+
#### 7. 显隐控制
|
|
273
|
+
|
|
274
|
+
使用 `<Show>` 控制元素显隐(隐藏时缓存 DOM 而非销毁,显示时从缓存恢复):
|
|
275
|
+
|
|
276
|
+
```html
|
|
277
|
+
<Show test="$data.isVisible">
|
|
278
|
+
<p>隐藏时 DOM 被缓存,显示时恢复,状态不丢失</p>
|
|
279
|
+
</Show>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
> **`<Show>` 是 `<If keepalive>` 的语法糖**,编译时自动转换为单分支 Conditional + keepalive。适合频繁切换且需要保持状态的场景。
|
|
283
|
+
>
|
|
284
|
+
> **`<Show>` vs `<If>`**:`<Show>` 隐藏时将 DOM 移入缓存,显示时从缓存恢复,状态保留;`<If>` 根据条件渲染对应分支,切换时销毁/重建 DOM,适合条件稳定或需要完整生命周期控制的场景。
|
|
285
|
+
|
|
286
|
+
兼容语法:
|
|
287
|
+
|
|
288
|
+
```html
|
|
289
|
+
<Show condition="$data.isVisible">
|
|
290
|
+
<p>隐藏时 DOM 被缓存,显示时恢复,状态不丢失</p>
|
|
291
|
+
</Show>
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
#### 8. 列表渲染
|
|
271
295
|
|
|
272
296
|
使用 `<For>` 渲染列表:
|
|
273
297
|
|
|
@@ -289,7 +313,26 @@ class MyCounter extends BaseElement<{ count: number }> {
|
|
|
289
313
|
</ul>
|
|
290
314
|
```
|
|
291
315
|
|
|
292
|
-
####
|
|
316
|
+
#### 9. 组件缓存
|
|
317
|
+
|
|
318
|
+
在 `<If>` / `<ElseIf>` / `<Else>` 上添加 `keepalive` 属性,条件不满足时将 DOM 移入缓存而非销毁,切换回来时从缓存恢复:
|
|
319
|
+
|
|
320
|
+
```html
|
|
321
|
+
<If test="$data.tab === 'list'" keepalive>
|
|
322
|
+
<my-heavy-list />
|
|
323
|
+
</If>
|
|
324
|
+
<ElseIf test="$data.tab === 'detail'" keepalive>
|
|
325
|
+
<my-detail-view />
|
|
326
|
+
</ElseIf>
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
> **`keepalive` vs 普通 `If`**:普通 `If` 切换时会销毁/重建 DOM,状态丢失;`keepalive` 切换时将 DOM 移入缓存,状态保留。适合标签页切换等需要保持组件状态的场景。
|
|
330
|
+
>
|
|
331
|
+
> **keepalive 生命周期**:keepalive 分支失活时触发 `deactivated`(而非 `unmounted`),恢复时触发 `activated`(而非 `mounted`)。LRU 缓存淘汰时触发 `unmounted`(永久销毁)。嵌套 keepalive 不受支持。
|
|
332
|
+
>
|
|
333
|
+
> **keepalive 语义说明**:恢复时执行完整的 Reconciliation——内部 `<If>`/`<For>` 会根据当前数据重新求值,动态属性和动态文本也会同步更新。分支内部因条件/列表变化产生的多余节点会触发 `unmounted` 并清理事件,而非错误地进入 keepalive 缓存。
|
|
334
|
+
|
|
335
|
+
#### 10. 动态类
|
|
293
336
|
|
|
294
337
|
使用 `:class` 动态控制 CSS 类(推荐):
|
|
295
338
|
|
|
@@ -307,7 +350,7 @@ class MyCounter extends BaseElement<{ count: number }> {
|
|
|
307
350
|
<div s-class="[$data.class1, $data.class2]">内容</div>
|
|
308
351
|
```
|
|
309
352
|
|
|
310
|
-
####
|
|
353
|
+
#### 11. 动态样式
|
|
311
354
|
|
|
312
355
|
使用 `:style` 动态设置样式(推荐):
|
|
313
356
|
|
|
@@ -345,7 +388,7 @@ solely/
|
|
|
345
388
|
|
|
346
389
|
1. **编译器**:将模板转换为高效的渲染函数,支持 AST 解析和中间表示优化
|
|
347
390
|
2. **运行时**:包含组件系统、响应式系统、渲染器和路由系统
|
|
348
|
-
3. **响应式系统**:基于 Proxy
|
|
391
|
+
3. **响应式系统**:基于 Proxy 的响应式数据绑定,采用 DAG 弱引用双向图和全局代理生成器自动追踪依赖,支持路径过滤、批量防抖与深度比较
|
|
349
392
|
4. **路由系统**:支持单页应用的路由管理,包括路由定义、导航和组件挂载
|
|
350
393
|
5. **插件系统**:提供扩展机制,支持自定义功能
|
|
351
394
|
|
|
@@ -710,33 +753,39 @@ document.body.appendChild(element);
|
|
|
710
753
|
|
|
711
754
|
Solely 提供了完整的生命周期钩子函数,用于在组件的不同阶段执行自定义逻辑:
|
|
712
755
|
|
|
713
|
-
| 钩子函数 | 调用时机 | 说明
|
|
714
|
-
| -------------------------------------------- | ----------------- |
|
|
715
|
-
| `created()` | 组件实例创建后 | 在组件构造函数执行完成后调用,此时组件尚未挂载到 DOM
|
|
716
|
-
| `mounted()` | 组件挂载到 DOM 后 | 组件首次渲染完成后调用,可在此进行 DOM 操作
|
|
717
|
-
| `
|
|
718
|
-
| `
|
|
719
|
-
| `
|
|
720
|
-
| `
|
|
721
|
-
| `
|
|
722
|
-
| `
|
|
723
|
-
| `
|
|
756
|
+
| 钩子函数 | 调用时机 | 说明 |
|
|
757
|
+
| -------------------------------------------- | ----------------- | ----------------------------------------------------------------- |
|
|
758
|
+
| `created()` | 组件实例创建后 | 在组件构造函数执行完成后调用,此时组件尚未挂载到 DOM |
|
|
759
|
+
| `mounted()` | 组件挂载到 DOM 后 | 组件首次渲染完成后调用,可在此进行 DOM 操作 |
|
|
760
|
+
| `beforeUpdate()` | 数据更新前 | 在组件数据更新导致重新渲染前调用 |
|
|
761
|
+
| `updated()` | 数据更新后 | 在组件数据更新导致重新渲染后调用 |
|
|
762
|
+
| `beforeAttributesUpdate()` | 属性更新前 | 在属性更新导致重新渲染前调用 |
|
|
763
|
+
| `afterAttributesUpdate()` | 属性更新后 | 在属性更新导致重新渲染后调用 |
|
|
764
|
+
| `attributeChanged(name, oldValue, newValue)` | 属性变化时 | 当组件的观察属性发生变化时调用,参数分别为属性名、旧值和新值 |
|
|
765
|
+
| `unmounted()` | 组件从 DOM 移除后 | 组件被永久销毁时调用(keepalive 缓存时不触发),可在此清理资源 |
|
|
766
|
+
| `activated()` | keepalive 恢复后 | keepalive 缓存的组件从缓存恢复到 DOM 时调用 |
|
|
767
|
+
| `deactivated()` | keepalive 缓存时 | keepalive 缓存的组件从 DOM 移入缓存时调用(临时失活,非永久销毁) |
|
|
724
768
|
|
|
725
769
|
#### 生命周期调用顺序
|
|
726
770
|
|
|
727
|
-
1. **组件创建阶段**:`created()` → `mounted()`
|
|
771
|
+
1. **组件创建阶段**:`created()` → `mounted()`
|
|
728
772
|
2. **数据更新阶段**:`beforeUpdate()` → 渲染更新 → `updated()`
|
|
729
773
|
3. **属性更新阶段**:`attributeChanged()` → `beforeAttributesUpdate()` → 渲染更新 → `updated()` → `afterAttributesUpdate()`
|
|
730
|
-
4. **组件销毁阶段**:`unmounted()`
|
|
774
|
+
4. **组件销毁阶段**:`unmounted()`(普通销毁)或 `deactivated()`(keepalive 缓存)
|
|
775
|
+
5. **keepalive 恢复阶段**:`activated()` → `beforeUpdate()` → 渲染更新 → `updated()`
|
|
776
|
+
|
|
777
|
+
> **迁移提示**:`onInit()` 生命周期钩子已移除,原有的异步初始化逻辑请迁移到 `mounted()` 中执行。
|
|
731
778
|
|
|
732
779
|
#### 模板级生命周期钩子
|
|
733
780
|
|
|
734
781
|
Solely 支持在组件模板的普通元素上定义生命周期钩子,用于在元素的挂载和更新时执行自定义逻辑:
|
|
735
782
|
|
|
736
|
-
| 钩子属性
|
|
737
|
-
|
|
|
738
|
-
| `mounted`
|
|
739
|
-
| `updated`
|
|
783
|
+
| 钩子属性 | 调用时机 | 说明 |
|
|
784
|
+
| ------------- | ---------------- | ---------------------------------------------------------------------- |
|
|
785
|
+
| `mounted` | 元素挂载后 | 在元素首次渲染完成后调用,可调用组件方法并接收元素本身作为参数 |
|
|
786
|
+
| `updated` | 元素更新后 | 在元素数据更新导致重新渲染后调用,可调用组件方法并接收元素本身作为参数 |
|
|
787
|
+
| `activated` | keepalive 恢复后 | keepalive 缓存的元素从缓存恢复到 DOM 时调用 |
|
|
788
|
+
| `deactivated` | keepalive 缓存时 | keepalive 缓存的元素从 DOM 移入缓存时调用 |
|
|
740
789
|
|
|
741
790
|
**示例**:
|
|
742
791
|
|
|
@@ -843,8 +892,8 @@ class MyComponent extends BaseElement<MyData> {
|
|
|
843
892
|
console.log(`属性 ${name} 从 ${oldValue} 变为 ${newValue}`);
|
|
844
893
|
}
|
|
845
894
|
|
|
846
|
-
//
|
|
847
|
-
async
|
|
895
|
+
// 组件挂载后调用,支持异步初始化
|
|
896
|
+
async mounted() {
|
|
848
897
|
console.log('组件初始化中');
|
|
849
898
|
// 可在此进行异步操作,如数据获取
|
|
850
899
|
await fetchData();
|
|
@@ -869,13 +918,13 @@ class MyComponent extends BaseElement<MyData> {
|
|
|
869
918
|
```typescript
|
|
870
919
|
import { observe } from 'solely';
|
|
871
920
|
|
|
872
|
-
const state = observe(
|
|
921
|
+
const { proxy: state } = observe(
|
|
873
922
|
{
|
|
874
923
|
name: 'Solely',
|
|
875
924
|
items: [1, 2, 3],
|
|
876
925
|
},
|
|
877
|
-
|
|
878
|
-
console.log('数据变化:',
|
|
926
|
+
change => {
|
|
927
|
+
console.log('数据变化:', change);
|
|
879
928
|
},
|
|
880
929
|
);
|
|
881
930
|
|
|
@@ -886,21 +935,20 @@ state.name = 'New Name'; // 触发回调
|
|
|
886
935
|
|
|
887
936
|
响应式系统会自动处理以下特殊情况:
|
|
888
937
|
|
|
889
|
-
| 对象类型 | 处理方式 | 说明
|
|
890
|
-
| ---------------------- | -------- |
|
|
891
|
-
| `Object.freeze()`
|
|
892
|
-
| `
|
|
893
|
-
| `
|
|
894
|
-
| `
|
|
895
|
-
| `
|
|
896
|
-
| `Response` / `Request` | 跳过代理 | Fetch API 对象不会被代理 |
|
|
938
|
+
| 对象类型 | 处理方式 | 说明 |
|
|
939
|
+
| ---------------------- | -------- | ------------------------------------------------------------------------------ |
|
|
940
|
+
| 不可扩展对象 | 跳过代理 | `Object.freeze()` / `Object.seal()` 等不可扩展的对象不会被代理,直接返回原对象 |
|
|
941
|
+
| `File` / `Blob` | 跳过代理 | 浏览器原生文件对象不会被代理 |
|
|
942
|
+
| `FormData` | 跳过代理 | 表单数据对象不会被代理 |
|
|
943
|
+
| `ArrayBuffer` | 跳过代理 | 二进制数据缓冲区不会被代理 |
|
|
944
|
+
| `Response` / `Request` | 跳过代理 | Fetch API 对象不会被代理 |
|
|
897
945
|
|
|
898
946
|
**示例**:
|
|
899
947
|
|
|
900
948
|
```typescript
|
|
901
949
|
// 冻结对象不会被代理
|
|
902
950
|
const frozen = Object.freeze({ count: 0 });
|
|
903
|
-
const state = observe({ frozen }, change => {
|
|
951
|
+
const { proxy: state } = observe({ frozen }, change => {
|
|
904
952
|
console.log('变化:', change);
|
|
905
953
|
});
|
|
906
954
|
|
|
@@ -909,7 +957,7 @@ state.frozen.count = 1; // 静默失败,无回调
|
|
|
909
957
|
|
|
910
958
|
// File 对象不会被代理
|
|
911
959
|
const file = new File(['content'], 'test.txt');
|
|
912
|
-
const state2 = observe({ file }, change => {
|
|
960
|
+
const { proxy: state2 } = observe({ file }, change => {
|
|
913
961
|
console.log('变化:', change);
|
|
914
962
|
});
|
|
915
963
|
|
|
@@ -917,6 +965,56 @@ const state2 = observe({ file }, change => {
|
|
|
917
965
|
console.log(state2.file instanceof File); // true
|
|
918
966
|
```
|
|
919
967
|
|
|
968
|
+
#### 配置选项
|
|
969
|
+
|
|
970
|
+
`observe` 支持通过第三个参数传入配置选项:
|
|
971
|
+
|
|
972
|
+
| 选项 | 类型 | 默认值 | 说明 |
|
|
973
|
+
| ------------- | --------------------------------- | ------- | -------------------------------------------------------------------------- |
|
|
974
|
+
| `throttle` | `number` | `0` | 变更回调的防抖间隔(毫秒),`0` 表示不防抖 |
|
|
975
|
+
| `immediate` | `boolean` | `false` | 是否在初始化时立即触发一次所有属性的 `set` 回调 |
|
|
976
|
+
| `filter` | `string \| string[]` | `[]` | 路径过滤规则,支持完整路径或父路径匹配(如 `'user'` 可匹配 `'user.name'`) |
|
|
977
|
+
| `deepCompare` | `boolean` | `false` | 是否对新旧值进行深度比较,避免无意义更新 |
|
|
978
|
+
| `onBatch` | `(changes: ChangeItem[]) => void` | - | 批量回调,在 `throttle` 间隔结束后一次性接收所有变更 |
|
|
979
|
+
|
|
980
|
+
#### 返回值
|
|
981
|
+
|
|
982
|
+
| 属性/方法 | 说明 |
|
|
983
|
+
| ------------- | ------------------------------------ |
|
|
984
|
+
| `proxy` | 响应式代理对象,修改其属性会触发回调 |
|
|
985
|
+
| `unobserve()` | 暂停观察,后续变更不再触发回调 |
|
|
986
|
+
| `resume()` | 恢复观察 |
|
|
987
|
+
| `dispose()` | 彻底销毁观察器,清理所有引用 |
|
|
988
|
+
|
|
989
|
+
#### 变更对象结构
|
|
990
|
+
|
|
991
|
+
回调接收的 `ChangeItem` 对象包含以下字段:
|
|
992
|
+
|
|
993
|
+
| 字段 | 说明 |
|
|
994
|
+
| ----------------------- | --------------------------------------------------------------------------------------- |
|
|
995
|
+
| `type` | 变更类型:`set`、`delete`、`array-push`、`array-splice`、`array-replace`、`array-reset` |
|
|
996
|
+
| `key` | 发生变更的属性键(数组变更类型除外) |
|
|
997
|
+
| `path` | 完整路径数组,从根对象到变更属性的全路径(**包含 `key`**) |
|
|
998
|
+
| `newValue` / `oldValue` | 新值与旧值(依变更类型而异) |
|
|
999
|
+
|
|
1000
|
+
**示例**:
|
|
1001
|
+
|
|
1002
|
+
```typescript
|
|
1003
|
+
const { proxy, unobserve, resume, dispose } = observe(
|
|
1004
|
+
{ user: { name: 'Solely' } },
|
|
1005
|
+
change => {
|
|
1006
|
+
console.log(`Change at ${change.path.join('.')}:`, change);
|
|
1007
|
+
},
|
|
1008
|
+
{ filter: 'user', throttle: 16 },
|
|
1009
|
+
);
|
|
1010
|
+
|
|
1011
|
+
proxy.user.name = 'New Name'; // 触发回调,path 为 ['user', 'name']
|
|
1012
|
+
unobserve(); // 暂停
|
|
1013
|
+
proxy.user.name = 'Another'; // 不触发
|
|
1014
|
+
resume(); // 恢复
|
|
1015
|
+
dispose(); // 彻底销毁
|
|
1016
|
+
```
|
|
1017
|
+
|
|
920
1018
|
### 路由系统
|
|
921
1019
|
|
|
922
1020
|
Solely 提供了功能强大的内置路由系统,支持单页应用开发,包括路由定义、导航、参数传递、路由守卫等功能。
|
|
@@ -1022,7 +1120,7 @@ const router = createRouter({
|
|
|
1022
1120
|
}
|
|
1023
1121
|
|
|
1024
1122
|
// 阻止导航
|
|
1025
|
-
if (to.
|
|
1123
|
+
if (to.fullPath === '/admin' && !isAdmin) {
|
|
1026
1124
|
return false;
|
|
1027
1125
|
}
|
|
1028
1126
|
|
|
@@ -1031,7 +1129,7 @@ const router = createRouter({
|
|
|
1031
1129
|
},
|
|
1032
1130
|
afterEach: (to, from) => {
|
|
1033
1131
|
// 导航完成后执行
|
|
1034
|
-
console.log('从', from
|
|
1132
|
+
console.log('从', from?.fullPath ?? '初始', '导航到', to.fullPath);
|
|
1035
1133
|
document.title = to.meta.title || 'Solely App';
|
|
1036
1134
|
},
|
|
1037
1135
|
});
|
|
@@ -1302,6 +1400,8 @@ npm run test:ui
|
|
|
1302
1400
|
npm run test:coverage
|
|
1303
1401
|
```
|
|
1304
1402
|
|
|
1403
|
+
> 当前测试套件包含 270+ 个单元测试,覆盖编译器、运行时、响应式系统、路由系统和组件接口等模块。
|
|
1404
|
+
|
|
1305
1405
|
## 🔧 构建和开发
|
|
1306
1406
|
|
|
1307
1407
|
```bash
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=Object.defineProperty,t=(t,n,o)=>((t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o)(t,"symbol"!=typeof n?n+"":n,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../shared/gen-function.cjs"),o=require("../../shared/env.cjs"),c=require("../../types/ast.cjs"),l=require("../../types/lifecycle.cjs"),i=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},r=new class{constructor(){t(this,"compilers",new Map)}get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new a,this.compilers.set(e,t)),t}clear(e){var t;if(e)null==(t=this.compilers.get(e))||t.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class a{constructor(){t(this,"cache",new Map),t(this,"functions",[])}makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(e,t,c){const l=null==t?void 0:t.trim();if(!l)return 0;const i=this.makeCacheKey(e,l,c),s=this.cache.get(i);if(void 0!==s)return s;let r;try{r=n.genFunction(l,e,c)}catch(u){o.IS_DEV&&console.error(`[Solely] IR Compile Error - Type: ${e}, Expr: "${l}"`,u),r=()=>""}const a=this.functions.push(r);return this.cache.set(i,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function u(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:l.isLifecycleKind(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function
|
|
1
|
+
"use strict";var e=Object.defineProperty,t=(t,n,o)=>((t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o)(t,"symbol"!=typeof n?n+"":n,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../shared/gen-function.cjs"),o=require("../../shared/env.cjs"),c=require("../../types/ast.cjs"),l=require("../../types/lifecycle.cjs"),i=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},r=new class{constructor(){t(this,"compilers",new Map)}get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new a,this.compilers.set(e,t)),t}clear(e){var t;if(e)null==(t=this.compilers.get(e))||t.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class a{constructor(){t(this,"cache",new Map),t(this,"functions",[])}makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(e,t,c){const l=null==t?void 0:t.trim();if(!l)return 0;const i=this.makeCacheKey(e,l,c),s=this.cache.get(i);if(void 0!==s)return s;let r;try{r=n.genFunction(l,e,c)}catch(u){o.IS_DEV&&console.error(`[Solely] IR Compile Error - Type: ${e}, Expr: "${l}"`,u),r=()=>""}const a=this.functions.push(r);return this.cache.set(i,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function u(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:l.isLifecycleKind(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function p(e,t,n){e.__m={expr:t??"",loc:n??void 0}}function d(e){if(!e.attrs)return;const t=e.attrs.find(e=>"s-model"===e.key);if(!t)return;const n=t.value.trim(),o=n.startsWith("$data.")?n:`$data.${n.replace(/^this\./,"")}`,c=t.loc,l=(e.tag||"").toLowerCase(),i=e.attrs.find(e=>"type"===e.key),r=(null==i?void 0:i.value)??"text";e.attrs=e.attrs.filter(e=>e!==t);const a=(t,n,o)=>{var l;null==(l=e.attrs)||l.push({key:t,value:n,role:o,loc:c})};if("input"===l){if("checkbox"===r){const t=e.attrs.find(e=>"value"===e.key),n=t?JSON.stringify(t.value):'"on"';return a(":checked",`Array.isArray(${o}) ? ${o}.includes(${n}) : ${o}`),void a("@change",`\n const _v = ${n};\n if(Array.isArray(${o})) {\n const _i = ${o}.indexOf(_v);\n if(checked && _i === -1) ${o}.push(_v);\n else if(!checked && _i > -1) ${o}.splice(_i,1);\n } else {\n ${o} = checked;\n }`,"model")}if("radio"===r){const t=e.attrs.find(e=>"value"===e.key),n=(null==t?void 0:t.value)??"null";return a(":checked",`${o} == ${JSON.stringify(n)}`),void a("@change",`if (checked) ${o} = ${JSON.stringify(n)}`,"model")}return a(":value",o),void a("@input",`${o} = value`,"model")}if("textarea"===l)return a(":value",o),void a("@input",`${o} = value`,"model");if("select"===l)return void(e.attrs.some(e=>"multiple"===e.key)?(a("updated",`\n const values = Array.isArray(${o}) ? ${o} : ${o} != null ? [${o}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),a("@change",`${o} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(a(":value",o),a("@change",`${o} = value`,"model")));const u=s[l],p=(null==u?void 0:u.prop)??"value",d=(null==u?void 0:u.event)??"change";a(`:${p}`,o),a(`@${d}`,`${o} = ${"checked"===p?"checked":"value"===p?"value":`event.target.${p}`}`,"model")}function f(e,t,n,o=null){if(!e.attrs||0===e.attrs.length)return[];const c=[];for(const l of e.attrs){if(o&&o.has(l.key))continue;const{key:i,value:s,role:r}=l,{isDynamic:a,type:d}=u(i);if(a&&d){const o={k:i,f:n.compile(d,s??"",t),d:1,r:r};p(o,s,l.loc??e.loc),c.push(o)}else c.push({k:i,v:s,d:0,r:r})}return c}function h(e){let t=0===e.d;if(e.c&&e.c.length>0)for(const n of e.c)h(n)||(t=!1);if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)h(e)||(t=!1);return!t||e.t!==c.ASTType.Element&&e.t!==c.ASTType.Text||(e.s=1),t}function y(e,t,n){var l,s,r,a,h,y;const m={t:e.type,d:0};let T=!1;var S;switch(e.type===c.ASTType.Text?(S=e.content)&&i.test(S)&&(T=!0):((null==(l=e.attrs)?void 0:l.some(e=>"s-model"===e.key||u(e.key).isDynamic))&&(T=!0),e.type===c.ASTType.For&&(T=!0)),m.d=T?1:0,e.type){case c.ASTType.Text:{const o=e.content??"";T?(m.f=n.compile("template",o,t),p(m,o,e.loc)):m.x=o;break}case c.ASTType.Element:m.g=e.tag,d(e),m.a=f(e,t,n),e.children&&(m.c=v(e.children,t,n));break;case c.ASTType.For:{const o=null==(s=e.attrs)?void 0:s.find(e=>"each"===e.key),c=(null==o?void 0:o.value)??"";m.f=n.compile("expression",c,t),m.i=(null==(a=null==(r=e.attrs)?void 0:r.find(e=>"item"===e.key))?void 0:a.value)??"item",m.n=(null==(y=null==(h=e.attrs)?void 0:h.find(e=>"index"===e.key))?void 0:y.value)??"index",p(m,c,(null==o?void 0:o.loc)??e.loc);const l=new Set(["each","item","index"]);m.a=f(e,t,n,l);const i=[...t,{i:m.i,x:m.n}];e.children&&(m.c=v(e.children,i,n));break}case c.ASTType.If:case c.ASTType.ElseIf:case c.ASTType.Else:case c.ASTType.Show:o.IS_DEV&&console.warn(`[Solely] Orphaned conditional node found: ${c.ASTType[e.type]}`),m.a=f(e,t,n),e.children&&(m.c=v(e.children,t,n));break;case c.ASTType.Comment:m.x=e.content??""}return m}function v(e,t,n){var o,l;const i=[];let s=0;for(;s<e.length;){const r=e[s];if(r.type===c.ASTType.If||r.type===c.ASTType.Show){const a=[];let u=s;for(;u<e.length;){const i=e[u],s=i.type;if(s!==c.ASTType.If&&s!==c.ASTType.ElseIf&&s!==c.ASTType.Else&&s!==c.ASTType.Show)break;if((s===c.ASTType.If||s===c.ASTType.Show)&&a.length>0)break;let r,p=null,d="";if(s!==c.ASTType.Else){const e=null==(o=i.attrs)?void 0:o.find(e=>"test"===e.key||"condition"===e.key);d=(null==e?void 0:e.value)??"false",p=n.compile("expression",d,t),r=(null==e?void 0:e.loc)??i.loc}const h=i.children?v(i.children,t,n):[],y=f(i,t,n,new Set(["test","condition","keepalive"])),m=s===c.ASTType.Show||(null==(l=i.attrs)?void 0:l.some(e=>"keepalive"===e.key));if(a.push({f:p,c:h,a:y.length>0?y:void 0,ka:m?1:void 0,__m:{expr:d,loc:r}}),u++,s===c.ASTType.Else||s===c.ASTType.Show)break}i.push({t:c.ASTType.Conditional,d:1,b:a,__m:{loc:r.loc}}),s=u}else i.push(y(r,t,n)),s++}return i}exports.buildIR=function(e,t={}){const{filename:n="anonymous",source:c}=t,l=r.get(n);l.clear();const i=performance.now(),s=v(e,[],l);for(const o of s)h(o);const a=performance.now(),u=l.getStats(),p=s.filter(e=>1===e.d).length,d=s.filter(e=>1===e.s).length,f={t:"root",v:"1.2.0",fns:l.getFunctions(),n:s,s:{tf:u.total,cf:u.cached,dn:p,tn:s.length,sn:d},m:{t:(new Date).toISOString(),as:e.length,fn:n,...c&&{src:c}}};return o.IS_DEV&&console.info(`[Solely] Compiled <${n}> in ${(a-i).toFixed(2)}ms | Nodes: ${s.length} | Fns: ${u.total} | StaticSubtrees: ${d}`),f},exports.clearIRCache=function(e){r.clear(e)},exports.transformModel=d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=(t,n,o)=>((t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o)(t,"symbol"!=typeof n?n+"":n,o);import{genFunction as n}from"../../shared/gen-function.js";import{IS_DEV as o}from"../../shared/env.js";import{ASTType as
|
|
1
|
+
var e=Object.defineProperty,t=(t,n,o)=>((t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o)(t,"symbol"!=typeof n?n+"":n,o);import{genFunction as n}from"../../shared/gen-function.js";import{IS_DEV as o}from"../../shared/env.js";import{ASTType as l}from"../../types/ast.js";import{isLifecycleKind as c}from"../../types/lifecycle.js";const i=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},r=new class{constructor(){t(this,"compilers",new Map)}get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new a,this.compilers.set(e,t)),t}clear(e){var t;if(e)null==(t=this.compilers.get(e))||t.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class a{constructor(){t(this,"cache",new Map),t(this,"functions",[])}makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(e,t,l){const c=null==t?void 0:t.trim();if(!c)return 0;const i=this.makeCacheKey(e,c,l),s=this.cache.get(i);if(void 0!==s)return s;let r;try{r=n(c,e,l)}catch(u){o&&console.error(`[Solely] IR Compile Error - Type: ${e}, Expr: "${c}"`,u),r=()=>""}const a=this.functions.push(r);return this.cache.set(i,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function u(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:c(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function d(e,t,n){e.__m={expr:t??"",loc:n??void 0}}function f(e){if(!e.attrs)return;const t=e.attrs.find(e=>"s-model"===e.key);if(!t)return;const n=t.value.trim(),o=n.startsWith("$data.")?n:`$data.${n.replace(/^this\./,"")}`,l=t.loc,c=(e.tag||"").toLowerCase(),i=e.attrs.find(e=>"type"===e.key),r=(null==i?void 0:i.value)??"text";e.attrs=e.attrs.filter(e=>e!==t);const a=(t,n,o)=>{var c;null==(c=e.attrs)||c.push({key:t,value:n,role:o,loc:l})};if("input"===c){if("checkbox"===r){const t=e.attrs.find(e=>"value"===e.key),n=t?JSON.stringify(t.value):'"on"';return a(":checked",`Array.isArray(${o}) ? ${o}.includes(${n}) : ${o}`),void a("@change",`\n const _v = ${n};\n if(Array.isArray(${o})) {\n const _i = ${o}.indexOf(_v);\n if(checked && _i === -1) ${o}.push(_v);\n else if(!checked && _i > -1) ${o}.splice(_i,1);\n } else {\n ${o} = checked;\n }`,"model")}if("radio"===r){const t=e.attrs.find(e=>"value"===e.key),n=(null==t?void 0:t.value)??"null";return a(":checked",`${o} == ${JSON.stringify(n)}`),void a("@change",`if (checked) ${o} = ${JSON.stringify(n)}`,"model")}return a(":value",o),void a("@input",`${o} = value`,"model")}if("textarea"===c)return a(":value",o),void a("@input",`${o} = value`,"model");if("select"===c)return void(e.attrs.some(e=>"multiple"===e.key)?(a("updated",`\n const values = Array.isArray(${o}) ? ${o} : ${o} != null ? [${o}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),a("@change",`${o} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(a(":value",o),a("@change",`${o} = value`,"model")));const u=s[c],d=(null==u?void 0:u.prop)??"value",f=(null==u?void 0:u.event)??"change";a(`:${d}`,o),a(`@${f}`,`${o} = ${"checked"===d?"checked":"value"===d?"value":`event.target.${d}`}`,"model")}function h(e,t,n,o=null){if(!e.attrs||0===e.attrs.length)return[];const l=[];for(const c of e.attrs){if(o&&o.has(c.key))continue;const{key:i,value:s,role:r}=c,{isDynamic:a,type:f}=u(i);if(a&&f){const o={k:i,f:n.compile(f,s??"",t),d:1,r:r};d(o,s,c.loc??e.loc),l.push(o)}else l.push({k:i,v:s,d:0,r:r})}return l}function p(e){let t=0===e.d;if(e.c&&e.c.length>0)for(const n of e.c)p(n)||(t=!1);if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)p(e)||(t=!1);return!t||e.t!==l.Element&&e.t!==l.Text||(e.s=1),t}function v(e,t,n){var c,s,r,a,p,v;const y={t:e.type,d:0};let $=!1;var g;switch(e.type===l.Text?(g=e.content)&&i.test(g)&&($=!0):((null==(c=e.attrs)?void 0:c.some(e=>"s-model"===e.key||u(e.key).isDynamic))&&($=!0),e.type===l.For&&($=!0)),y.d=$?1:0,e.type){case l.Text:{const o=e.content??"";$?(y.f=n.compile("template",o,t),d(y,o,e.loc)):y.x=o;break}case l.Element:y.g=e.tag,f(e),y.a=h(e,t,n),e.children&&(y.c=m(e.children,t,n));break;case l.For:{const o=null==(s=e.attrs)?void 0:s.find(e=>"each"===e.key),l=(null==o?void 0:o.value)??"";y.f=n.compile("expression",l,t),y.i=(null==(a=null==(r=e.attrs)?void 0:r.find(e=>"item"===e.key))?void 0:a.value)??"item",y.n=(null==(v=null==(p=e.attrs)?void 0:p.find(e=>"index"===e.key))?void 0:v.value)??"index",d(y,l,(null==o?void 0:o.loc)??e.loc);const c=new Set(["each","item","index"]);y.a=h(e,t,n,c);const i=[...t,{i:y.i,x:y.n}];e.children&&(y.c=m(e.children,i,n));break}case l.If:case l.ElseIf:case l.Else:case l.Show:o&&console.warn(`[Solely] Orphaned conditional node found: ${l[e.type]}`),y.a=h(e,t,n),e.children&&(y.c=m(e.children,t,n));break;case l.Comment:y.x=e.content??""}return y}function m(e,t,n){var o,c;const i=[];let s=0;for(;s<e.length;){const r=e[s];if(r.type===l.If||r.type===l.Show){const a=[];let u=s;for(;u<e.length;){const i=e[u],s=i.type;if(s!==l.If&&s!==l.ElseIf&&s!==l.Else&&s!==l.Show)break;if((s===l.If||s===l.Show)&&a.length>0)break;let r,d=null,f="";if(s!==l.Else){const e=null==(o=i.attrs)?void 0:o.find(e=>"test"===e.key||"condition"===e.key);f=(null==e?void 0:e.value)??"false",d=n.compile("expression",f,t),r=(null==e?void 0:e.loc)??i.loc}const p=i.children?m(i.children,t,n):[],v=h(i,t,n,new Set(["test","condition","keepalive"])),y=s===l.Show||(null==(c=i.attrs)?void 0:c.some(e=>"keepalive"===e.key));if(a.push({f:d,c:p,a:v.length>0?v:void 0,ka:y?1:void 0,__m:{expr:f,loc:r}}),u++,s===l.Else||s===l.Show)break}i.push({t:l.Conditional,d:1,b:a,__m:{loc:r.loc}}),s=u}else i.push(v(r,t,n)),s++}return i}function y(e,t={}){const{filename:n="anonymous",source:l}=t,c=r.get(n);c.clear();const i=performance.now(),s=m(e,[],c);for(const o of s)p(o);const a=performance.now(),u=c.getStats(),d=s.filter(e=>1===e.d).length,f=s.filter(e=>1===e.s).length,h={t:"root",v:"1.2.0",fns:c.getFunctions(),n:s,s:{tf:u.total,cf:u.cached,dn:d,tn:s.length,sn:f},m:{t:(new Date).toISOString(),as:e.length,fn:n,...l&&{src:l}}};return o&&console.info(`[Solely] Compiled <${n}> in ${(a-i).toFixed(2)}ms | Nodes: ${s.length} | Fns: ${u.total} | StaticSubtrees: ${f}`),h}function $(e){r.clear(e)}export{y as buildIR,$ as clearIRCache,f as transformModel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../shared/event-listeners.cjs"),e=require("../../types/ast.cjs"),n=require("../../types/lifecycle.cjs"),s=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../shared/event-listeners.cjs"),e=require("../../types/ast.cjs"),n=require("../../types/lifecycle.cjs"),s=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,o=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function i(o,i){var c;const l=(null==(c=(o.match(s)||[])[1])?void 0:c.toLowerCase())??"",a=function(e,s){r.lastIndex=0;const o=[];let i;const c=e.replace(/^\s*[^\s"'/>]+/,""),l=e.length-c.length;for(;null!==(i=r.exec(c));){const r=i[1];if(!r)continue;const c=i[2]??i[3]??i[4]??"";let a=r;t.default.has(r)&&(a=a.replace(/^on/,"@")),"s-model"!==a&&(a=a.replace(/^on-/,"@").replace(/^s-/,":")),a=n.mapAttrKeyToLifecycleKind(a)||a;const h=i[0],f=h.indexOf("=");let p;if(-1===f)p=h.indexOf(r)+r.length;else{let t=f+1;for(;t<h.length&&/\s/.test(h[t]);)t++;if('"'===h[t]||"'"===h[t]){let e=t+1;for(;e<h.length&&/\s/.test(h[e]);)e++;p=e}else{let e=t;for(;e<h.length&&/\s/.test(h[e]);)e++;p=e}}const u=i.index+p+l,g=e.slice(0,u).split("\n"),T=s[0]+g.length-1,y=g.length>1?g[g.length-1].length+1:s[1]+u;o.push({key:a,value:c,loc:[T,y]})}return o}(o,i);return{type:{for:e.ASTType.For,if:e.ASTType.If,elseif:e.ASTType.ElseIf,else:e.ASTType.Else,show:e.ASTType.Show}[l]??e.ASTType.Element,tag:l,loc:i,children:[],attrs:a}}function c(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let s=!1,o=!1,r=e;for(;r<n;){const e=t[r];if("'"!==e||o)if('"'!==e||s){if(">"===e&&!s&&!o)return r}else o=!o;else s=!s;r++}return-1}exports.parseHtml=function(t){var n,r;const l=[];if(!t)return[];const a=[],h=()=>{var t;return 0===a.length?l:(t=a[a.length-1]).children||(t.children=[])};let f=0;const p=t.length,u=[0];let g=0;for(;-1!==(g=t.indexOf("\n",g));)u.push(++g);function T(t){let e=0,n=u.length-1;for(;e<=n;){const s=e+n>>>1;u[s]<=t?e=s+1:n=s-1}return[n+1,t-u[n]+1]}for(;f<p;){const l=t.indexOf("<",f);if(-1===l||l>f){const n=t.substring(f,-1===l?void 0:l),s=a.length>0?a[a.length-1]:null;let o,r;if(!s||"pre"!==s.tag&&"code"!==s.tag&&"textarea"!==s.tag&&"script"!==s.tag&&"style"!==s.tag){if(o=n.trim(),""===o){if(f=l,-1===l)break;continue}r=f+(n.length-n.trimStart().length)}else o=n,r=f;const i=h(),c=i[i.length-1];if(c&&c.type===e.ASTType.Text)c.content+=o;else{const t=T(r);i.push({type:e.ASTType.Text,tag:"text",content:o,loc:t,children:[]})}if(-1===l)break;f=l}const u=c(t,f+1);if(-1===u){const n=t.substring(f);n.trim()&&h().push({type:e.ASTType.Text,tag:"text",content:n.trim(),children:[],loc:T(f)});break}const g=t.substring(f,u+1),y=h(),d=T(f);if(g.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(4,-3),loc:d,children:[]}),f=u+1;continue}if(g.startsWith("<![CDATA[")){y.push({type:e.ASTType.Text,tag:"text",content:g.slice(9,-3),loc:d,children:[]}),f=u+1;continue}if(g.startsWith("<!")&&!g.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(2,-1),loc:d,children:[]}),f=u+1;continue}if(g.startsWith("<?")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(2,-2),loc:d,children:[]}),f=u+1;continue}if(g.startsWith("</")){const t=null==(n=(g.match(s)||[])[1])?void 0:n.toLowerCase();if(t){let e=-1;for(let n=a.length-1;n>=0;n--)if((null==(r=a[n].tag)?void 0:r.toLowerCase())===t){e=n;break}-1!==e&&(a.length=e)}f=u+1;continue}const x=i(g,d);y.push(x);const m=x.tag||"",A=m.toLowerCase().startsWith("script"),S=m.toLowerCase().startsWith("style"),b=g.endsWith("/>")||o.has(m.toLowerCase());if((A||S)&&!b){const n=`</${m}>`,s=t.toLowerCase().indexOf(n,u+1);if(-1!==s){const o=t.substring(u+1,s);o.length&&x.children.push({type:e.ASTType.Text,tag:"text",content:o,loc:T(u+1),children:[]}),f=s+n.length;continue}{const n=t.substring(u+1);n.length&&x.children.push({type:e.ASTType.Text,tag:"text",content:n,loc:T(u+1),children:[]}),f=p;continue}}b||x.type===e.ASTType.Text||x.type===e.ASTType.Comment||a.push(x),f=u+1}return l};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"../../shared/event-listeners.js";import{ASTType as e}from"../../types/ast.js";import{mapAttrKeyToLifecycleKind as n}from"../../types/lifecycle.js";const s=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,o=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function i(o,i){var l;const c=(null==(l=(o.match(s)||[])[1])?void 0:l.toLowerCase())??"",h=function(e,s){r.lastIndex=0;const o=[];let i;const l=e.replace(/^\s*[^\s"'/>]+/,""),c=e.length-l.length;for(;null!==(i=r.exec(l));){const r=i[1];if(!r)continue;const l=i[2]??i[3]??i[4]??"";let h=r;t.has(r)&&(h=h.replace(/^on/,"@")),"s-model"!==h&&(h=h.replace(/^on-/,"@").replace(/^s-/,":")),h=n(h)||h;const a=i[0],f=a.indexOf("=");let u;if(-1===f)u=a.indexOf(r)+r.length;else{let t=f+1;for(;t<a.length&&/\s/.test(a[t]);)t++;if('"'===a[t]||"'"===a[t]){let e=t+1;for(;e<a.length&&/\s/.test(a[e]);)e++;u=e}else{let e=t;for(;e<a.length&&/\s/.test(a[e]);)e++;u=e}}const g=i.index+u+c,p=e.slice(0,g).split("\n"),d=s[0]+p.length-1,m=p.length>1?p[p.length-1].length+1:s[1]+g;o.push({key:h,value:l,loc:[d,m]})}return o}(o,i);return{type:{for:e.For,if:e.If,elseif:e.ElseIf,else:e.Else}[c]??e.Element,tag:c,loc:i,children:[],attrs:h}}function l(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let s=!1,o=!1,r=e;for(;r<n;){const e=t[r];if("'"!==e||o)if('"'!==e||s){if(">"===e&&!s&&!o)return r}else o=!o;else s=!s;r++}return-1}function c(t){var n,r;const c=[];if(!t)return[];const h=[],a=()=>{var t;return 0===h.length?c:(t=h[h.length-1]).children||(t.children=[])};let f=0;const u=t.length,g=[0];let p=0;for(;-1!==(p=t.indexOf("\n",p));)g.push(++p);function d(t){let e=0,n=g.length-1;for(;e<=n;){const s=e+n>>>1;g[s]<=t?e=s+1:n=s-1}return[n+1,t-g[n]+1]}for(;f<u;){const c=t.indexOf("<",f);if(-1===c||c>f){const n=t.substring(f,-1===c?void 0:c),s=h.length>0?h[h.length-1]:null;let o,r;if(!s||"pre"!==s.tag&&"code"!==s.tag&&"textarea"!==s.tag&&"script"!==s.tag&&"style"!==s.tag){if(o=n.trim(),""===o){if(f=c,-1===c)break;continue}r=f+(n.length-n.trimStart().length)}else o=n,r=f;const i=a(),l=i[i.length-1];if(l&&l.type===e.Text)l.content+=o;else{const t=d(r);i.push({type:e.Text,tag:"text",content:o,loc:t,children:[]})}if(-1===c)break;f=c}const g=l(t,f+1);if(-1===g){const n=t.substring(f);n.trim()&&a().push({type:e.Text,tag:"text",content:n.trim(),children:[],loc:d(f)});break}const p=t.substring(f,g+1),m=a(),x=d(f);if(p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(4,-3),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<![CDATA[")){m.push({type:e.Text,tag:"text",content:p.slice(9,-3),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<!")&&!p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-1),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<?")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-2),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("</")){const t=null==(n=(p.match(s)||[])[1])?void 0:n.toLowerCase();if(t){let e=-1;for(let n=h.length-1;n>=0;n--)if((null==(r=h[n].tag)?void 0:r.toLowerCase())===t){e=n;break}-1!==e&&(h.length=e)}f=g+1;continue}const y=i(p,x);m.push(y);const b=y.tag||"",C=b.toLowerCase().startsWith("script"),
|
|
1
|
+
import t from"../../shared/event-listeners.js";import{ASTType as e}from"../../types/ast.js";import{mapAttrKeyToLifecycleKind as n}from"../../types/lifecycle.js";const s=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,o=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function i(o,i){var l;const c=(null==(l=(o.match(s)||[])[1])?void 0:l.toLowerCase())??"",h=function(e,s){r.lastIndex=0;const o=[];let i;const l=e.replace(/^\s*[^\s"'/>]+/,""),c=e.length-l.length;for(;null!==(i=r.exec(l));){const r=i[1];if(!r)continue;const l=i[2]??i[3]??i[4]??"";let h=r;t.has(r)&&(h=h.replace(/^on/,"@")),"s-model"!==h&&(h=h.replace(/^on-/,"@").replace(/^s-/,":")),h=n(h)||h;const a=i[0],f=a.indexOf("=");let u;if(-1===f)u=a.indexOf(r)+r.length;else{let t=f+1;for(;t<a.length&&/\s/.test(a[t]);)t++;if('"'===a[t]||"'"===a[t]){let e=t+1;for(;e<a.length&&/\s/.test(a[e]);)e++;u=e}else{let e=t;for(;e<a.length&&/\s/.test(a[e]);)e++;u=e}}const g=i.index+u+c,p=e.slice(0,g).split("\n"),d=s[0]+p.length-1,m=p.length>1?p[p.length-1].length+1:s[1]+g;o.push({key:h,value:l,loc:[d,m]})}return o}(o,i);return{type:{for:e.For,if:e.If,elseif:e.ElseIf,else:e.Else,show:e.Show}[c]??e.Element,tag:c,loc:i,children:[],attrs:h}}function l(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let s=!1,o=!1,r=e;for(;r<n;){const e=t[r];if("'"!==e||o)if('"'!==e||s){if(">"===e&&!s&&!o)return r}else o=!o;else s=!s;r++}return-1}function c(t){var n,r;const c=[];if(!t)return[];const h=[],a=()=>{var t;return 0===h.length?c:(t=h[h.length-1]).children||(t.children=[])};let f=0;const u=t.length,g=[0];let p=0;for(;-1!==(p=t.indexOf("\n",p));)g.push(++p);function d(t){let e=0,n=g.length-1;for(;e<=n;){const s=e+n>>>1;g[s]<=t?e=s+1:n=s-1}return[n+1,t-g[n]+1]}for(;f<u;){const c=t.indexOf("<",f);if(-1===c||c>f){const n=t.substring(f,-1===c?void 0:c),s=h.length>0?h[h.length-1]:null;let o,r;if(!s||"pre"!==s.tag&&"code"!==s.tag&&"textarea"!==s.tag&&"script"!==s.tag&&"style"!==s.tag){if(o=n.trim(),""===o){if(f=c,-1===c)break;continue}r=f+(n.length-n.trimStart().length)}else o=n,r=f;const i=a(),l=i[i.length-1];if(l&&l.type===e.Text)l.content+=o;else{const t=d(r);i.push({type:e.Text,tag:"text",content:o,loc:t,children:[]})}if(-1===c)break;f=c}const g=l(t,f+1);if(-1===g){const n=t.substring(f);n.trim()&&a().push({type:e.Text,tag:"text",content:n.trim(),children:[],loc:d(f)});break}const p=t.substring(f,g+1),m=a(),x=d(f);if(p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(4,-3),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<![CDATA[")){m.push({type:e.Text,tag:"text",content:p.slice(9,-3),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<!")&&!p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-1),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<?")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-2),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("</")){const t=null==(n=(p.match(s)||[])[1])?void 0:n.toLowerCase();if(t){let e=-1;for(let n=h.length-1;n>=0;n--)if((null==(r=h[n].tag)?void 0:r.toLowerCase())===t){e=n;break}-1!==e&&(h.length=e)}f=g+1;continue}const y=i(p,x);m.push(y);const b=y.tag||"",C=b.toLowerCase().startsWith("script"),w=b.toLowerCase().startsWith("style"),W=p.endsWith("/>")||o.has(b.toLowerCase());if((C||w)&&!W){const n=`</${b}>`,s=t.toLowerCase().indexOf(n,g+1);if(-1!==s){const o=t.substring(g+1,s);o.length&&y.children.push({type:e.Text,tag:"text",content:o,loc:d(g+1),children:[]}),f=s+n.length;continue}{const n=t.substring(g+1);n.length&&y.children.push({type:e.Text,tag:"text",content:n,loc:d(g+1),children:[]}),f=u;continue}}W||y.type===e.Text||y.type===e.Comment||h.push(y),f=g+1}return c}export{c as parseHtml};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=Object.defineProperty,e=(e,s,a)=>((e,s,a)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[s]=a)(e,"symbol"!=typeof s?s+"":s,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./style.css.cjs"),a=require("./index.html.cjs"),l=require("../../../runtime/component/base-element.cjs"),i=require("../../../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;exports.SolelySelect=class extends l.default{constructor(){super(...arguments),e(this,"clickOutsideHandler"),e(this,"slotObserver"),e(this,"closeTimer")}get value(){return this.$data.value||""}set value(t){this.$data.disabled||this.setValue(t)}getSelectClasses(){const t={};return"small"===this.$data.size?t["select--sm"]=!0:"large"===this.$data.size?t["select--lg"]=!0:t["select--md"]=!0,t["is-disabled"]=!!this.$data.disabled,t["is-focused"]=!!this.$data.focused,t["is-open"]=!!this.$data.isOpen,t["use-slot"]=this.$data.useSlot,t}getDropdownClasses(){return{"select__dropdown--closing":!!this.$data.closing,"select__dropdown--top":"top"===this.$data.dropdownPlacement,"select__dropdown--bottom":"bottom"===this.$data.dropdownPlacement}}getOptionClasses(t){return{"select__option--selected":t.value===this.$data.value,"select__option--disabled":!!t.disabled}}calculateDropdownPlacement(){const t=this.getBoundingClientRect(),e=window.innerHeight-t.bottom,s=t.top;this.$data.dropdownPlacement=e<256&&s>e?"top":"bottom"}collectSlotOptions(){const t=Array.from(this.children);this.$data.hasHeaderSlot=t.some(t=>"header"===t.getAttribute("slot")),this.$data.hasFooterSlot=t.some(t=>"footer"===t.getAttribute("slot"));const e=t.filter(t=>!t.getAttribute("slot")&&t.hasAttribute("data-value"));0!==e.length?(this.$data.useSlot=!0,this.$data.slotOptions=e.map(t=>{var e;const s=t;return{value:s.getAttribute("data-value")||"",label:s.getAttribute("data-label")||(null==(e=s.textContent)?void 0:e.trim())||"",disabled:s.hasAttribute("disabled"),element:t}}),this.
|
|
1
|
+
"use strict";var t=Object.defineProperty,e=(e,s,a)=>((e,s,a)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[s]=a)(e,"symbol"!=typeof s?s+"":s,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./style.css.cjs"),a=require("./index.html.cjs"),l=require("../../../runtime/component/base-element.cjs"),i=require("../../../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;exports.SolelySelect=class extends l.default{constructor(){super(...arguments),e(this,"clickOutsideHandler"),e(this,"slotObserver"),e(this,"closeTimer")}get value(){return this.$data.value||""}set value(t){this.$data.disabled||this.setValue(t)}getSelectClasses(){const t={};return"small"===this.$data.size?t["select--sm"]=!0:"large"===this.$data.size?t["select--lg"]=!0:t["select--md"]=!0,t["is-disabled"]=!!this.$data.disabled,t["is-focused"]=!!this.$data.focused,t["is-open"]=!!this.$data.isOpen,t["use-slot"]=this.$data.useSlot,t}getDropdownClasses(){return{"select__dropdown--closing":!!this.$data.closing,"select__dropdown--top":"top"===this.$data.dropdownPlacement,"select__dropdown--bottom":"bottom"===this.$data.dropdownPlacement}}getOptionClasses(t){return{"select__option--selected":t.value===this.$data.value,"select__option--disabled":!!t.disabled}}calculateDropdownPlacement(){const t=this.getBoundingClientRect(),e=window.innerHeight-t.bottom,s=t.top;this.$data.dropdownPlacement=e<256&&s>e?"top":"bottom"}collectSlotOptions(){const t=Array.from(this.children);this.$data.hasHeaderSlot=t.some(t=>"header"===t.getAttribute("slot")),this.$data.hasFooterSlot=t.some(t=>"footer"===t.getAttribute("slot"));const e=t.filter(t=>!t.getAttribute("slot")&&t.hasAttribute("data-value"));0!==e.length?(this.$data.useSlot=!0,this.$data.slotOptions=e.map(t=>{var e;const s=t;return{value:s.getAttribute("data-value")||"",label:s.getAttribute("data-label")||(null==(e=s.textContent)?void 0:e.trim())||"",disabled:s.hasAttribute("disabled"),element:t}}),this.syncSelectedLabel()):this.$data.useSlot=!1}mounted(){this.collectSlotOptions(),this.$data.useSlot||this.parseOptions(),this.setupSlotObserver(),this.clickOutsideHandler=t=>{t.composedPath().some(t=>t===this)||this.closeDropdown()},document.addEventListener("click",this.clickOutsideHandler)}setupSlotObserver(){this.slotObserver=new MutationObserver(()=>{this.collectSlotOptions()}),this.slotObserver.observe(this,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["data-value","data-label","disabled"]})}unmounted(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.slotObserver&&this.slotObserver.disconnect(),this.closeTimer&&(clearTimeout(this.closeTimer),this.closeTimer=void 0)}updated(){const t=this.$data.selectedLabel,e=this.getCurrentLabel();t!==e&&(this.$data.selectedLabel=e),this.updateAriaAttributes()}updateAriaAttributes(){var t;const e=null==(t=this.shadowRoot)?void 0:t.querySelector(".select__trigger");e&&(e.setAttribute("aria-expanded",this.$data.isOpen?"true":"false"),e.setAttribute("aria-disabled",this.$data.disabled?"true":"false"))}getCurrentLabel(){if(this.$data.useSlot){const t=this.$data.slotOptions.find(t=>t.value===this.$data.value);return(null==t?void 0:t.label)||""}{const t=this.$data.parsedOptions.find(t=>t.value===this.$data.value);return(null==t?void 0:t.label)||""}}parseOptions(){this.$data.parsedOptions=Array.isArray(this.$data.options)?this.$data.options:[],this.syncSelectedLabel()}syncSelectedLabel(){var t,e;if(this.$data.useSlot){const e=null==(t=this.$data.slotOptions)?void 0:t.find(t=>t.value===this.$data.value);this.$data.selectedLabel=(null==e?void 0:e.label)||""}else{const t=null==(e=this.$data.parsedOptions)?void 0:e.find(t=>t.value===this.$data.value);this.$data.selectedLabel=(null==t?void 0:t.label)||""}}handleClick(){if(this.$data.disabled)return;const t=!this.$data.isOpen;this.$data.isOpen=t,this.$data.focused=t,t&&this.calculateDropdownPlacement()}handleSelect(t,e){t.disabled||(this.$data.value=t.value,this.syncSelectedLabel(),this.closeDropdown(),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})))}handleSlotClick(t){var e;const s=t.target.closest("[data-value]");if(!s)return;if(s.hasAttribute("data-group"))return void t.stopPropagation();const a=s.getAttribute("data-value")||"",l=s.getAttribute("data-label")||(null==(e=s.textContent)?void 0:e.trim())||"";s.hasAttribute("disabled")||(this.$data.value=a,this.$data.selectedLabel=l,this.closeDropdown(),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})))}handleHeaderFooterClick(t){t.stopPropagation()}handleClear(t){t.stopPropagation(),this.$data.value="",this.$data.selectedLabel="",this.dispatchEvent(new Event("clear",{bubbles:!0,composed:!0})),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0}))}closeDropdown(){this.$data.isOpen&&(this.$data.closing=!0,this.closeTimer=setTimeout(()=>{this.$data.isOpen=!1,this.$data.closing=!1,this.$data.focused=!1,this.closeTimer=void 0},200))}setValue(t,e=!1){this.$data.value=t,this.syncSelectedLabel(),e||this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0}))}getValue(){return this.$data.value||""}setOptions(t){this.$data.options=t,this.$data.useSlot=!1,this.parseOptions()}},exports.SolelySelect=((t,e)=>{for(var s,a=e,l=t.length-1;l>=0;l--)(s=t[l])&&(a=s(a)||a);return a})([i.CustomElement({tagName:"solely-select",template:a.__SOLELY_IR__,styles:s.default,shadowDOM:{use:!0,mode:"open"},props:[{name:"value",type:"string",default:""},{name:"placeholder",type:"string",default:"请选择"},{name:"disabled",type:"boolean",default:!1},{name:"size",type:"string",default:"medium"},{name:"clearable",type:"boolean",default:!1},{name:"options",type:"array",default:[]},{name:"multiple",type:"boolean",default:!1},{name:"block",type:"boolean",default:!1}]})],exports.SolelySelect);
|
|
@@ -49,10 +49,6 @@ declare class SolelySelect extends BaseElement<SelectProps & {
|
|
|
49
49
|
* 从插槽收集选项
|
|
50
50
|
*/
|
|
51
51
|
collectSlotOptions(): void;
|
|
52
|
-
/**
|
|
53
|
-
* 从插槽更新选中的标签
|
|
54
|
-
*/
|
|
55
|
-
updateSelectedLabelFromSlot(): void;
|
|
56
52
|
mounted(): void;
|
|
57
53
|
/**
|
|
58
54
|
* 设置插槽观察器
|
|
@@ -76,7 +72,7 @@ declare class SolelySelect extends BaseElement<SelectProps & {
|
|
|
76
72
|
/**
|
|
77
73
|
* 更新选中的标签
|
|
78
74
|
*/
|
|
79
|
-
|
|
75
|
+
syncSelectedLabel(): void;
|
|
80
76
|
/**
|
|
81
77
|
* 点击事件处理
|
|
82
78
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=Object.defineProperty,e=(e,a
|
|
1
|
+
var t=Object.defineProperty,e=(e,s,a)=>((e,s,a)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[s]=a)(e,"symbol"!=typeof s?s+"":s,a);import s from"./style.css.js";import{__SOLELY_IR__ as a}from"./index.html.js";import i from"../../../runtime/component/base-element.js";import{CustomElement as l}from"../../../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;let o=class extends i{constructor(){super(...arguments),e(this,"clickOutsideHandler"),e(this,"slotObserver"),e(this,"closeTimer")}get value(){return this.$data.value||""}set value(t){this.$data.disabled||this.setValue(t)}getSelectClasses(){const t={};return"small"===this.$data.size?t["select--sm"]=!0:"large"===this.$data.size?t["select--lg"]=!0:t["select--md"]=!0,t["is-disabled"]=!!this.$data.disabled,t["is-focused"]=!!this.$data.focused,t["is-open"]=!!this.$data.isOpen,t["use-slot"]=this.$data.useSlot,t}getDropdownClasses(){return{"select__dropdown--closing":!!this.$data.closing,"select__dropdown--top":"top"===this.$data.dropdownPlacement,"select__dropdown--bottom":"bottom"===this.$data.dropdownPlacement}}getOptionClasses(t){return{"select__option--selected":t.value===this.$data.value,"select__option--disabled":!!t.disabled}}calculateDropdownPlacement(){const t=this.getBoundingClientRect(),e=window.innerHeight-t.bottom,s=t.top;this.$data.dropdownPlacement=e<256&&s>e?"top":"bottom"}collectSlotOptions(){const t=Array.from(this.children);this.$data.hasHeaderSlot=t.some(t=>"header"===t.getAttribute("slot")),this.$data.hasFooterSlot=t.some(t=>"footer"===t.getAttribute("slot"));const e=t.filter(t=>!t.getAttribute("slot")&&t.hasAttribute("data-value"));0!==e.length?(this.$data.useSlot=!0,this.$data.slotOptions=e.map(t=>{var e;const s=t;return{value:s.getAttribute("data-value")||"",label:s.getAttribute("data-label")||(null==(e=s.textContent)?void 0:e.trim())||"",disabled:s.hasAttribute("disabled"),element:t}}),this.syncSelectedLabel()):this.$data.useSlot=!1}mounted(){this.collectSlotOptions(),this.$data.useSlot||this.parseOptions(),this.setupSlotObserver(),this.clickOutsideHandler=t=>{t.composedPath().some(t=>t===this)||this.closeDropdown()},document.addEventListener("click",this.clickOutsideHandler)}setupSlotObserver(){this.slotObserver=new MutationObserver(()=>{this.collectSlotOptions()}),this.slotObserver.observe(this,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["data-value","data-label","disabled"]})}unmounted(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler),this.slotObserver&&this.slotObserver.disconnect(),this.closeTimer&&(clearTimeout(this.closeTimer),this.closeTimer=void 0)}updated(){const t=this.$data.selectedLabel,e=this.getCurrentLabel();t!==e&&(this.$data.selectedLabel=e),this.updateAriaAttributes()}updateAriaAttributes(){var t;const e=null==(t=this.shadowRoot)?void 0:t.querySelector(".select__trigger");e&&(e.setAttribute("aria-expanded",this.$data.isOpen?"true":"false"),e.setAttribute("aria-disabled",this.$data.disabled?"true":"false"))}getCurrentLabel(){if(this.$data.useSlot){const t=this.$data.slotOptions.find(t=>t.value===this.$data.value);return(null==t?void 0:t.label)||""}{const t=this.$data.parsedOptions.find(t=>t.value===this.$data.value);return(null==t?void 0:t.label)||""}}parseOptions(){this.$data.parsedOptions=Array.isArray(this.$data.options)?this.$data.options:[],this.syncSelectedLabel()}syncSelectedLabel(){var t,e;if(this.$data.useSlot){const e=null==(t=this.$data.slotOptions)?void 0:t.find(t=>t.value===this.$data.value);this.$data.selectedLabel=(null==e?void 0:e.label)||""}else{const t=null==(e=this.$data.parsedOptions)?void 0:e.find(t=>t.value===this.$data.value);this.$data.selectedLabel=(null==t?void 0:t.label)||""}}handleClick(){if(this.$data.disabled)return;const t=!this.$data.isOpen;this.$data.isOpen=t,this.$data.focused=t,t&&this.calculateDropdownPlacement()}handleSelect(t,e){t.disabled||(this.$data.value=t.value,this.syncSelectedLabel(),this.closeDropdown(),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})))}handleSlotClick(t){var e;const s=t.target.closest("[data-value]");if(!s)return;if(s.hasAttribute("data-group"))return void t.stopPropagation();const a=s.getAttribute("data-value")||"",i=s.getAttribute("data-label")||(null==(e=s.textContent)?void 0:e.trim())||"";s.hasAttribute("disabled")||(this.$data.value=a,this.$data.selectedLabel=i,this.closeDropdown(),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})))}handleHeaderFooterClick(t){t.stopPropagation()}handleClear(t){t.stopPropagation(),this.$data.value="",this.$data.selectedLabel="",this.dispatchEvent(new Event("clear",{bubbles:!0,composed:!0})),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0}))}closeDropdown(){this.$data.isOpen&&(this.$data.closing=!0,this.closeTimer=setTimeout(()=>{this.$data.isOpen=!1,this.$data.closing=!1,this.$data.focused=!1,this.closeTimer=void 0},200))}setValue(t,e=!1){this.$data.value=t,this.syncSelectedLabel(),e||this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0}))}getValue(){return this.$data.value||""}setOptions(t){this.$data.options=t,this.$data.useSlot=!1,this.parseOptions()}};o=((t,e)=>{for(var s,a=e,i=t.length-1;i>=0;i--)(s=t[i])&&(a=s(a)||a);return a})([l({tagName:"solely-select",template:a,styles:s,shadowDOM:{use:!0,mode:"open"},props:[{name:"value",type:"string",default:""},{name:"placeholder",type:"string",default:"请选择"},{name:"disabled",type:"boolean",default:!1},{name:"size",type:"string",default:"medium"},{name:"clearable",type:"boolean",default:!1},{name:"options",type:"array",default:[]},{name:"multiple",type:"boolean",default:!1},{name:"block",type:"boolean",default:!1}]})],o);export{o as SolelySelect};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./router/index.cjs"),r=require("./shared/templateError.cjs"),t=require("./shared/gen-function.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./router/index.cjs"),r=require("./shared/templateError.cjs"),t=require("./shared/gen-function.cjs"),o=require("./shared/functions.cjs"),s=require("./shared/event-listeners.cjs"),c=require("./shared/is-object.cjs"),i=require("./shared/url.cjs"),u=require("./shared/env.cjs"),a=require("./shared/case-convert.cjs"),p=require("./types/ast.cjs"),n=require("./types/lifecycle.cjs"),l=require("./runtime/component/base-element.cjs"),d=require("./router/router-link.cjs"),x=require("./router/router-view.cjs"),m=require("./runtime/renderer/html-decode.cjs"),R=require("./runtime/component/decorators.cjs"),j=require("./runtime/renderer/renderIR.cjs"),y=require("./router/core.cjs"),q=require("./compiler/ir/buildIR.cjs"),h=require("./runtime/reactivity/computed.cjs"),b=require("./runtime/reactivity/observe.cjs"),f=require("./compiler/parser/parser.cjs"),E=require("./runtime/reactivity/watch.cjs");exports.createRouter=e.createRouter,exports.showTemplateError=r.showTemplateError,exports.genFunction=t.genFunction,exports.createFunction=o.createFunction,exports.isCSPBlocked=o.isCSPBlocked,exports.listeners=s.default,exports.isObject=c.isObject,exports.parseHashUrl=i.parseHashUrl,exports.IS_DEV=u.IS_DEV,exports.IS_PROD=u.IS_PROD,exports.SOLELY_VERSION=u.SOLELY_VERSION,exports.camelToKebab=a.camelToKebab,exports.ASTType=p.ASTType,exports.LIFECYCLE_ATTRS_MAP=n.LIFECYCLE_ATTRS_MAP,exports.isLifecycleKind=n.isLifecycleKind,exports.mapAttrKeyToLifecycleKind=n.mapAttrKeyToLifecycleKind,exports.BaseElement=l.default,Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>d.default}),Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>x.default}),exports.htmlDecode=m.default,exports.CustomElement=R.CustomElement,exports.IRRenderer=j.IRRenderer,exports.createRender=j.createRender,exports.Router=y.Router,exports.getRouter=y.getRouter,exports.routerReady=y.routerReady,exports.buildIR=q.buildIR,exports.clearIRCache=q.clearIRCache,exports.transformModel=q.transformModel,exports.computed=h.computed,exports.isProxy=b.isProxy,exports.observe=b.observe,exports.toProxy=b.toProxy,exports.toRaw=b.toRaw,exports.parseHtml=f.parseHtml,exports.watch=E.watch,exports.watchGetter=E.watchGetter;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRouter as r}from"./router/index.js";import{showTemplateError as e}from"./shared/templateError.js";import{genFunction as o}from"./shared/gen-function.js";import{createFunction as t,isCSPBlocked as m}from"./shared/functions.js";import{default as s}from"./shared/event-listeners.js";import{isObject as i}from"./shared/is-object.js";import{parseHashUrl as a}from"./shared/url.js";import{IS_DEV as p,IS_PROD as f}from"./shared/env.js";import{camelToKebab as
|
|
1
|
+
import{createRouter as r}from"./router/index.js";import{showTemplateError as e}from"./shared/templateError.js";import{genFunction as o}from"./shared/gen-function.js";import{createFunction as t,isCSPBlocked as m}from"./shared/functions.js";import{default as s}from"./shared/event-listeners.js";import{isObject as i}from"./shared/is-object.js";import{parseHashUrl as a}from"./shared/url.js";import{IS_DEV as p,IS_PROD as f,SOLELY_VERSION as n}from"./shared/env.js";import{camelToKebab as u}from"./shared/case-convert.js";import{ASTType as j}from"./types/ast.js";import{LIFECYCLE_ATTRS_MAP as d,isLifecycleKind as c,mapAttrKeyToLifecycleKind as l}from"./types/lifecycle.js";import{default as h}from"./runtime/component/base-element.js";import{default as v}from"./router/router-link.js";import{default as y}from"./router/router-view.js";import{default as b}from"./runtime/renderer/html-decode.js";import{CustomElement as R}from"./runtime/component/decorators.js";import{IRRenderer as w,createRender as k}from"./runtime/renderer/renderIR.js";import{Router as x,getRouter as E,routerReady as I}from"./router/core.js";import{buildIR as g,clearIRCache as B,transformModel as D}from"./compiler/ir/buildIR.js";import{computed as L}from"./runtime/reactivity/computed.js";import{isProxy as V,observe as q,toProxy as z,toRaw as A}from"./runtime/reactivity/observe.js";import{parseHtml as C}from"./compiler/parser/parser.js";import{watch as F,watchGetter as G}from"./runtime/reactivity/watch.js";export{j as ASTType,h as BaseElement,R as CustomElement,w as IRRenderer,p as IS_DEV,f as IS_PROD,d as LIFECYCLE_ATTRS_MAP,x as Router,v as RouterLink,y as RouterView,n as SOLELY_VERSION,g as buildIR,u as camelToKebab,B as clearIRCache,L as computed,t as createFunction,k as createRender,r as createRouter,o as genFunction,E as getRouter,b as htmlDecode,m as isCSPBlocked,c as isLifecycleKind,i as isObject,V as isProxy,s as listeners,l as mapAttrKeyToLifecycleKind,q as observe,a as parseHashUrl,C as parseHtml,I as routerReady,e as showTemplateError,z as toProxy,A as toRaw,D as transformModel,F as watch,G as watchGetter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("magic-string"),n=require("../compiler/parser/parser.cjs"),o=require("../compiler/ir/buildIR.cjs"),r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function t(e,r="anonymous"){const t=n.parseHtml(e);return o.buildIR(t,{filename:r,source:e})}function p(e,n){return(Array.isArray(n)?n:[n]).some(n=>"string"==typeof n?e.includes(n):n.test(e))}function i(n,o,r){const t=new e.default(n),p=n.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return t.overwrite(0,n.length,`\nconst __SOLELY_TEMPLATE__ = \`${p}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:t.toString(),map:t.generateMap({source:o,includeContent:!r})}}function l(n={}){const o={...r,...n};return{name:"solely-vite-plugin",enforce:"pre",configResolved(e){o.debug&&console.info("[Solely] Plugin initialized with options:",o)},transform(n,r){if(!p(r,o.include)||p(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug&&console.info(`[Solely] Processing: ${r}`),o.precompile){const p=t(n,r),i=function(n,o,r,t){const p=new e.default(o);p.remove(0,o.length),t||(p.append("\n// ============================================\n"),p.append("// Solely Precompiled Template\n"),p.append(`// Compiled at: ${(new Date).toISOString()}\n`),p.append("// ============================================\n\n")),p.append("const __SOLELY_IR__ = {\n"),p.append(" t: 'root',\n"),p.append(` v: '${n.v}',\n\n`),t||p.append(" // 编译后的函数数组\n"),p.append(" fns: [\n"),n.fns.forEach((e,o)=>{const r="string"==typeof e?e:e.toString(),i=o===n.fns.length-1;t||p.append(` // Function ${o+1}\n`),p.append(` ${r}${i?"":","}\n`)}),p.append(" ],\n\n");const i=e=>{const n={t:e.t,d:e.d};return void 0!==e.s&&(n.s=e.s),void 0!==e.g&&(n.g=e.g),void 0!==e.x&&(n.x=e.x),void 0!==e.f&&(n.f=e.f),void 0!==e.i&&(n.i=e.i),void 0!==e.n&&(n.n=e.n),!t&&e.__m&&(n.__m={...e.__m}),e.a&&(n.a=e.a.map(e=>({k:e.k,v:e.v,f:e.f,d:e.d,r:e.r,...!t&&e.__m&&{__m:{...e.__m}}}))),e.c&&(n.c=e.c.map(i)),e.b&&(n.b=e.b.map(e=>{var n;return{f:e.f,c:e.c.map(i),a:null==(n=e.a)?void 0:n.map(e=>({k:e.k,v:e.v,f:e.f,d:e.d,r:e.r})),...!t&&e.__m&&{__m:{...e.__m}}}})),n},l=n.n.map(i);return t||p.append(" // IR 节点树\n"),p.append(` n: ${JSON.stringify(l,null,t?0:2)},\n\n`),t||p.append(" // 编译统计\n"),p.append(` s: ${JSON.stringify(n.s)},\n\n`),t||(p.append(" // 元数据\n"),p.append(` m: ${JSON.stringify(n.m)}\n`)),p.append("};\n\n"),t||p.append("// 导出 IR 对象\n"),p.append("export default __SOLELY_IR__;\n"),p.append("export { __SOLELY_IR__ };\n\n"),t||p.append("// 同时导出模板字符串(向后兼容)\n"),p.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:p.toString(),map:p.generateMap({source:r,includeContent:!t,hires:!t})}}(p,n,r,!!o.minify);return o.debug&&(console.info(`[Solely] Compiled IR for: ${r}`),console.info("[Solely] Stats:",p.s)),{code:i.code,map:o.sourceMap?i.map:null}}{const e=i(n,r,!!o.minify);return{code:e.code,map:o.sourceMap?e.map:null}}}catch(l){const e=`[Solely] Error processing ${r}: ${l instanceof Error?l.message:String(l)}`;console.error(e),console.warn(`[Solely] Falling back to raw template for: ${r}`);const t=i(n,r,!!o.minify);return{code:t.code,map:o.sourceMap?t.map:null}}},handleHotUpdate({file:e,server:n,modules:r}){if(p(e,o.include)&&!p(e,o.exclude))return o.debug&&console.info(`[Solely] HMR triggered for: ${e}`),n.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=l),exports.compileTemplate=t,exports.solelyVitePlugin=l;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("magic-string"),n=require("../compiler/parser/parser.cjs"),o=require("../compiler/ir/buildIR.cjs"),r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function t(e,r="anonymous"){const t=n.parseHtml(e);return o.buildIR(t,{filename:r,source:e})}function p(e,n){return(Array.isArray(n)?n:[n]).some(n=>"string"==typeof n?e.includes(n):n.test(e))}function i(n,o,r){const t=new e.default(n),p=n.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return t.overwrite(0,n.length,`\nconst __SOLELY_TEMPLATE__ = \`${p}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:t.toString(),map:t.generateMap({source:o,includeContent:!r})}}function l(n={}){const o={...r,...n};return{name:"solely-vite-plugin",enforce:"pre",configResolved(e){o.debug&&console.info("[Solely] Plugin initialized with options:",o)},transform(n,r){if(!p(r,o.include)||p(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug&&console.info(`[Solely] Processing: ${r}`),o.precompile){const p=t(n,r),i=function(n,o,r,t){const p=new e.default(o);p.remove(0,o.length),t||(p.append("\n// ============================================\n"),p.append("// Solely Precompiled Template\n"),p.append(`// Compiled at: ${(new Date).toISOString()}\n`),p.append("// ============================================\n\n")),p.append("const __SOLELY_IR__ = {\n"),p.append(" t: 'root',\n"),p.append(` v: '${n.v}',\n\n`),t||p.append(" // 编译后的函数数组\n"),p.append(" fns: [\n"),n.fns.forEach((e,o)=>{const r="string"==typeof e?e:e.toString(),i=o===n.fns.length-1;t||p.append(` // Function ${o+1}\n`),p.append(` ${r}${i?"":","}\n`)}),p.append(" ],\n\n");const i=e=>{const n={t:e.t,d:e.d};return void 0!==e.s&&(n.s=e.s),void 0!==e.g&&(n.g=e.g),void 0!==e.x&&(n.x=e.x),void 0!==e.f&&(n.f=e.f),void 0!==e.i&&(n.i=e.i),void 0!==e.n&&(n.n=e.n),!t&&e.__m&&(n.__m={...e.__m}),e.a&&(n.a=e.a.map(e=>({k:e.k,v:e.v,f:e.f,d:e.d,r:e.r,...!t&&e.__m&&{__m:{...e.__m}}}))),e.c&&(n.c=e.c.map(i)),e.b&&(n.b=e.b.map(e=>{var n;return{f:e.f,c:e.c.map(i),a:null==(n=e.a)?void 0:n.map(e=>({k:e.k,v:e.v,f:e.f,d:e.d,r:e.r})),...void 0!==e.ka&&{ka:e.ka},...!t&&e.__m&&{__m:{...e.__m}}}})),n},l=n.n.map(i);return t||p.append(" // IR 节点树\n"),p.append(` n: ${JSON.stringify(l,null,t?0:2)},\n\n`),t||p.append(" // 编译统计\n"),p.append(` s: ${JSON.stringify(n.s)},\n\n`),t||(p.append(" // 元数据\n"),p.append(` m: ${JSON.stringify(n.m)}\n`)),p.append("};\n\n"),t||p.append("// 导出 IR 对象\n"),p.append("export default __SOLELY_IR__;\n"),p.append("export { __SOLELY_IR__ };\n\n"),t||p.append("// 同时导出模板字符串(向后兼容)\n"),p.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:p.toString(),map:p.generateMap({source:r,includeContent:!t,hires:!t})}}(p,n,r,!!o.minify);return o.debug&&(console.info(`[Solely] Compiled IR for: ${r}`),console.info("[Solely] Stats:",p.s)),{code:i.code,map:o.sourceMap?i.map:null}}{const e=i(n,r,!!o.minify);return{code:e.code,map:o.sourceMap?e.map:null}}}catch(l){const e=`[Solely] Error processing ${r}: ${l instanceof Error?l.message:String(l)}`;console.error(e),console.warn(`[Solely] Falling back to raw template for: ${r}`);const t=i(n,r,!!o.minify);return{code:t.code,map:o.sourceMap?t.map:null}}},handleHotUpdate({file:e,server:n,modules:r}){if(p(e,o.include)&&!p(e,o.exclude))return o.debug&&console.info(`[Solely] HMR triggered for: ${e}`),n.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=l),exports.compileTemplate=t,exports.solelyVitePlugin=l;
|