@puresnake/snake-ui 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/changelog.md +83 -0
- package/components/snake-activity-list/snake-activity-list.vue +365 -0
- package/components/snake-activity-list/types.ts +29 -0
- package/components/snake-auxiliary-segmentation/snake-auxiliary-segmentation.vue +44 -0
- package/components/snake-auxiliary-segmentation/types.ts +5 -0
- package/components/snake-button/snake-button.vue +357 -0
- package/components/snake-button/types.ts +103 -0
- package/components/snake-button-sort/snake-button-sort.vue +72 -0
- package/components/snake-button-sort/types.ts +22 -0
- package/components/snake-calendar/snake-calendar.vue +998 -0
- package/components/snake-calendar/types.ts +189 -0
- package/components/snake-cell-group/snake-cell-group.vue +55 -0
- package/components/snake-cell-group/types.ts +19 -0
- package/components/snake-cell-item/snake-cell-item.vue +159 -0
- package/components/snake-cell-item/types.ts +66 -0
- package/components/snake-checkbox/snake-checkbox.vue +264 -0
- package/components/snake-checkbox/types.ts +70 -0
- package/components/snake-checkbox-group/snake-checkbox-group.vue +154 -0
- package/components/snake-checkbox-group/types.ts +52 -0
- package/components/snake-cms/blocks/v2/cms-v2-carousel.vue +87 -0
- package/components/snake-cms/blocks/v2/cms-v2-coupon.vue +25 -0
- package/components/snake-cms/blocks/v2/cms-v2-custom.vue +12 -0
- package/components/snake-cms/blocks/v2/cms-v2-divider.vue +33 -0
- package/components/snake-cms/blocks/v2/cms-v2-floatbutton.vue +28 -0
- package/components/snake-cms/blocks/v2/cms-v2-goods-list.vue +150 -0
- package/components/snake-cms/blocks/v2/cms-v2-hotzone.vue +41 -0
- package/components/snake-cms/blocks/v2/cms-v2-images.vue +41 -0
- package/components/snake-cms/blocks/v2/cms-v2-magiccube.vue +93 -0
- package/components/snake-cms/blocks/v2/cms-v2-notice.vue +80 -0
- package/components/snake-cms/blocks/v2/cms-v2-popup.vue +46 -0
- package/components/snake-cms/blocks/v2/cms-v2-richtext.vue +18 -0
- package/components/snake-cms/blocks/v2/cms-v2-search.vue +115 -0
- package/components/snake-cms/blocks/v2/cms-v2-video.vue +25 -0
- package/components/snake-cms/blocks/v2/shared.ts +84 -0
- package/components/snake-cms/snake-cms.vue +409 -0
- package/components/snake-cms/types.ts +50 -0
- package/components/snake-commodity-search/snake-commodity-search.vue +234 -0
- package/components/snake-commodity-search/types.ts +11 -0
- package/components/snake-config-provider/snake-config-provider.vue +61 -0
- package/components/snake-config-provider/types.ts +22 -0
- package/components/snake-count-down/snake-count-down.vue +231 -0
- package/components/snake-count-down/types.ts +103 -0
- package/components/snake-coupon/snake-coupon.vue +209 -0
- package/components/snake-coupon/types.ts +21 -0
- package/components/snake-custom-module/snake-custom-module.vue +25 -0
- package/components/snake-custom-module/types.ts +11 -0
- package/components/snake-drop-menu/snake-drop-menu.vue +123 -0
- package/components/snake-drop-menu/types.ts +95 -0
- package/components/snake-drop-menu-item/snake-drop-menu-item.vue +181 -0
- package/components/snake-drop-menu-item/types.ts +48 -0
- package/components/snake-empty/snake-empty.vue +100 -0
- package/components/snake-empty/types.ts +48 -0
- package/components/snake-filter-sorts/filter-page.vue +695 -0
- package/components/snake-filter-sorts/snake-filter-sorts.vue +185 -0
- package/components/snake-filter-sorts/types.ts +57 -0
- package/components/snake-floating-bubble/snake-floating-bubble.vue +157 -0
- package/components/snake-floating-bubble/types.ts +43 -0
- package/components/snake-follow/snake-follow.vue +18 -0
- package/components/snake-follow/types.ts +2 -0
- package/components/snake-form/snake-form.vue +124 -0
- package/components/snake-form/types.ts +96 -0
- package/components/snake-form-item/snake-form-item.vue +331 -0
- package/components/snake-form-item/types.ts +70 -0
- package/components/snake-goods-list/snake-goods-list.vue +792 -0
- package/components/snake-goods-list/types.ts +55 -0
- package/components/snake-graphic-navigation/snake-graphic-navigation.vue +198 -0
- package/components/snake-graphic-navigation/types.ts +43 -0
- package/components/snake-icon/icon-names.ts +222 -0
- package/components/snake-icon/snake-icon.vue +220 -0
- package/components/snake-icon/types.ts +45 -0
- package/components/snake-image/snake-image.vue +230 -0
- package/components/snake-image/types.ts +70 -0
- package/components/snake-images/snake-images.vue +80 -0
- package/components/snake-images/types.ts +5 -0
- package/components/snake-index-anchor/snake-index-anchor.vue +83 -0
- package/components/snake-index-anchor/types.ts +14 -0
- package/components/snake-index-list/anchor-registry.ts +80 -0
- package/components/snake-index-list/snake-index-list.vue +259 -0
- package/components/snake-index-list/types.ts +115 -0
- package/components/snake-index-list-panel/snake-index-list-panel.vue +277 -0
- package/components/snake-index-list-panel/types.ts +10 -0
- package/components/snake-input/snake-input.vue +225 -0
- package/components/snake-input/types.ts +99 -0
- package/components/snake-jump-applet/snake-jump-applet.vue +99 -0
- package/components/snake-jump-applet/types.ts +17 -0
- package/components/snake-line/snake-line.vue +42 -0
- package/components/snake-line/types.ts +30 -0
- package/components/snake-line-progress/snake-line-progress.vue +105 -0
- package/components/snake-line-progress/types.ts +26 -0
- package/components/snake-link/snake-link.vue +74 -0
- package/components/snake-link/types.ts +30 -0
- package/components/snake-list-switching/components/tree-select/index.vue +156 -0
- package/components/snake-list-switching/snake-list-switching.vue +1285 -0
- package/components/snake-list-switching/types.ts +11 -0
- package/components/snake-loading/snake-loading.vue +241 -0
- package/components/snake-loading/types.ts +34 -0
- package/components/snake-loadmore/snake-loadmore.vue +103 -0
- package/components/snake-loadmore/types.ts +56 -0
- package/components/snake-magic-cube/snake-magic-cube.vue +622 -0
- package/components/snake-magic-cube/types.ts +5 -0
- package/components/snake-modal/snake-modal.vue +434 -0
- package/components/snake-modal/types.ts +71 -0
- package/components/snake-navbar/snake-navbar.vue +194 -0
- package/components/snake-navbar/types.ts +54 -0
- package/components/snake-no-network/snake-no-network.vue +125 -0
- package/components/snake-no-network/types.ts +27 -0
- package/components/snake-notice/snake-notice.vue +44 -0
- package/components/snake-notice/types.ts +5 -0
- package/components/snake-notice-bar/snake-notice-bar.vue +336 -0
- package/components/snake-notice-bar/types.ts +82 -0
- package/components/snake-overlay/snake-overlay.vue +73 -0
- package/components/snake-overlay/types.ts +35 -0
- package/components/snake-page-popup/snake-page-popup.vue +146 -0
- package/components/snake-page-popup/types.ts +28 -0
- package/components/snake-parse/audio/audio.vue +286 -0
- package/components/snake-parse/audio/context.js +11 -0
- package/components/snake-parse/audio/index.js +34 -0
- package/components/snake-parse/node/node.vue +830 -0
- package/components/snake-parse/parser.js +1480 -0
- package/components/snake-parse/snake-parse.vue +548 -0
- package/components/snake-parse/static/app-plus/snake-parse/js/handler.js +109 -0
- package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.js +0 -0
- package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.min.js +1 -0
- package/components/snake-parse/static/app-plus/snake-parse/local.html +3 -0
- package/components/snake-parse/style/index.js +132 -0
- package/components/snake-parse/style/parser.js +175 -0
- package/components/snake-parse/types.ts +49 -0
- package/components/snake-picture-ads/snake-picture-ads.vue +292 -0
- package/components/snake-picture-ads/types.ts +5 -0
- package/components/snake-popup/snake-popup.vue +348 -0
- package/components/snake-popup/types.ts +88 -0
- package/components/snake-qr-code/qrcode.ts +1214 -0
- package/components/snake-qr-code/snake-qr-code.vue +408 -0
- package/components/snake-qr-code/types.ts +78 -0
- package/components/snake-radio/snake-radio.vue +271 -0
- package/components/snake-radio/types.ts +64 -0
- package/components/snake-radio-group/snake-radio-group.vue +98 -0
- package/components/snake-radio-group/types.ts +48 -0
- package/components/snake-read-more/snake-read-more.vue +140 -0
- package/components/snake-read-more/types.ts +53 -0
- package/components/snake-rich-text/snake-rich-text.vue +24 -0
- package/components/snake-rich-text/types.ts +5 -0
- package/components/snake-root-portal/snake-root-portal.vue +92 -0
- package/components/snake-root-portal/types.ts +9 -0
- package/components/snake-search/snake-search.vue +202 -0
- package/components/snake-search/types.ts +84 -0
- package/components/snake-select/snake-select.vue +371 -0
- package/components/snake-select/types.ts +75 -0
- package/components/snake-skeleton/snake-skeleton.vue +104 -0
- package/components/snake-skeleton/types.ts +32 -0
- package/components/snake-skeleton-item/snake-skeleton-item.vue +90 -0
- package/components/snake-skeleton-item/types.ts +30 -0
- package/components/snake-slider/snake-slider.vue +249 -0
- package/components/snake-slider/types.ts +59 -0
- package/components/snake-sticky/snake-sticky.vue +178 -0
- package/components/snake-sticky/types.ts +48 -0
- package/components/snake-subsection/snake-subsection.vue +188 -0
- package/components/snake-subsection/types.ts +54 -0
- package/components/snake-swiper/snake-swiper.vue +229 -0
- package/components/snake-swiper/types.ts +79 -0
- package/components/snake-switch/snake-switch.vue +100 -0
- package/components/snake-switch/types.ts +41 -0
- package/components/snake-tabbar/snake-tabbar.vue +306 -0
- package/components/snake-tabbar/types.ts +93 -0
- package/components/snake-tabs/snake-tabs.vue +305 -0
- package/components/snake-tabs/types.ts +79 -0
- package/components/snake-text/snake-text.vue +292 -0
- package/components/snake-text/types.ts +100 -0
- package/components/snake-textarea/snake-textarea.vue +171 -0
- package/components/snake-textarea/types.ts +79 -0
- package/components/snake-toast/snake-toast.vue +330 -0
- package/components/snake-toast/types.ts +55 -0
- package/components/snake-tooltip/position.ts +33 -0
- package/components/snake-tooltip/snake-tooltip.vue +339 -0
- package/components/snake-tooltip/types.ts +80 -0
- package/components/snake-transition/snake-transition.vue +315 -0
- package/components/snake-transition/types.ts +65 -0
- package/components/snake-upload/snake-upload.vue +1801 -0
- package/components/snake-upload/types.ts +256 -0
- package/components/snake-videos/snake-videos.vue +122 -0
- package/components/snake-videos/types.ts +7 -0
- package/iconfont.css +881 -0
- package/index.d.ts +7 -0
- package/index.scss +26 -0
- package/index.ts +94 -0
- package/libs/cms/blocks.ts +103 -0
- package/libs/cms/config.ts +25 -0
- package/libs/cms/index.ts +7 -0
- package/libs/cms/normalize.ts +135 -0
- package/libs/cms/resolve.ts +12 -0
- package/libs/cms/types.ts +164 -0
- package/libs/cms/use-commerce.ts +385 -0
- package/libs/cms/v2.ts +193 -0
- package/libs/config/index.ts +4 -0
- package/libs/config/modal.ts +93 -0
- package/libs/config/state.ts +33 -0
- package/libs/config/theme.ts +351 -0
- package/libs/config/toast.ts +71 -0
- package/libs/config/types.ts +135 -0
- package/libs/config/zIndex.ts +44 -0
- package/libs/css/color.scss +105 -0
- package/libs/css/common.scss +171 -0
- package/libs/css/style.h5.scss +7 -0
- package/libs/css/style.mp.scss +7 -0
- package/libs/css/style.theme.scss +70 -0
- package/libs/css/style.vue.scss +140 -0
- package/libs/form/async-validator.min.d.ts +75 -0
- package/libs/form/async-validator.min.js +3 -0
- package/libs/form/index.ts +3 -0
- package/libs/form/path.ts +40 -0
- package/libs/form/types.ts +51 -0
- package/libs/form/validate.ts +149 -0
- package/libs/foundation.ts +96 -0
- package/libs/function/$parent.ts +33 -0
- package/libs/function/clipboard.ts +13 -0
- package/libs/function/color.ts +55 -0
- package/libs/function/debounce.ts +34 -0
- package/libs/function/deepClone.ts +30 -0
- package/libs/function/deepMerge.ts +25 -0
- package/libs/function/emitter.ts +30 -0
- package/libs/function/format.ts +27 -0
- package/libs/function/getParent.ts +53 -0
- package/libs/function/getRect.ts +29 -0
- package/libs/function/guid.ts +11 -0
- package/libs/function/index.ts +31 -0
- package/libs/function/queryParams.ts +73 -0
- package/libs/function/random.ts +6 -0
- package/libs/function/randomArray.ts +14 -0
- package/libs/function/route.ts +155 -0
- package/libs/function/sleep.ts +7 -0
- package/libs/function/style.ts +58 -0
- package/libs/function/styleUtils.ts +83 -0
- package/libs/function/system.ts +14 -0
- package/libs/function/test.ts +202 -0
- package/libs/function/throttle.ts +36 -0
- package/libs/function/timeFormat.ts +27 -0
- package/libs/function/timeFrom.ts +27 -0
- package/libs/function/toast.ts +10 -0
- package/libs/function/trim.ts +11 -0
- package/libs/function/type2icon.ts +11 -0
- package/libs/function/unit.ts +45 -0
- package/libs/hooks/index.ts +11 -0
- package/libs/hooks/useChildren.ts +125 -0
- package/libs/hooks/useColor.ts +5 -0
- package/libs/hooks/useDebounce.ts +5 -0
- package/libs/hooks/useLocale.ts +13 -0
- package/libs/hooks/useModal.ts +131 -0
- package/libs/hooks/useParent.ts +62 -0
- package/libs/hooks/useRect.ts +44 -0
- package/libs/hooks/useRouter.ts +5 -0
- package/libs/hooks/useTheme.ts +31 -0
- package/libs/hooks/useThrottle.ts +5 -0
- package/libs/hooks/useToast.ts +116 -0
- package/libs/index.ts +18 -0
- package/libs/request/auto-http.ts +1 -0
- package/libs/request/index.ts +343 -0
- package/libs/runtime/accessors.ts +55 -0
- package/libs/runtime/context.ts +40 -0
- package/libs/runtime/index.ts +18 -0
- package/libs/runtime/types.ts +49 -0
- package/libs/util/calendar.ts +6 -0
- package/locale/index.ts +130 -0
- package/locale/lang/en-US.ts +67 -0
- package/locale/lang/zh-CN.ts +67 -0
- package/package.json +134 -5
- package/plugins/index.ts +1 -0
- package/plugins/root/README.md +86 -0
- package/plugins/root/index.ts +123 -0
- package/plugins/root/page.ts +77 -0
- package/plugins/root/root.ts +53 -0
- package/plugins/root/utils.ts +137 -0
- package/readme.md +79 -0
- package/theme.scss +118 -0
- package/types/components.d.ts +236 -0
- package/types/global.d.ts +21 -0
- package/types/index.d.ts +6 -0
- package/types/uni-app.d.ts +16 -0
- package/README.md +0 -3
package/index.d.ts
ADDED
package/index.scss
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// 主题 token 单一事实来源(CSS 变量 + SCSS 桥接)
|
|
2
|
+
@import './theme.scss';
|
|
3
|
+
|
|
4
|
+
// 页面级主题应用(page 基础色 / 暗色选择器 / color-scheme / picker-view 修正)
|
|
5
|
+
@import './libs/css/style.theme.scss';
|
|
6
|
+
|
|
7
|
+
// 布局与间距工具类(flex / 字号 / 0-80 margin-padding 循环)
|
|
8
|
+
@import './libs/css/common.scss';
|
|
9
|
+
|
|
10
|
+
// 功能色与文字色工具类
|
|
11
|
+
@import './libs/css/color.scss';
|
|
12
|
+
|
|
13
|
+
// vue 页面通用工具类(line-clamp / 1px 边框 / safe-area / reset-button)
|
|
14
|
+
/* #ifndef APP-NVUE */
|
|
15
|
+
@import './libs/css/style.vue.scss';
|
|
16
|
+
/* #endif */
|
|
17
|
+
|
|
18
|
+
// 小程序特有的样式
|
|
19
|
+
/* #ifdef MP */
|
|
20
|
+
@import './libs/css/style.mp.scss';
|
|
21
|
+
/* #endif */
|
|
22
|
+
|
|
23
|
+
// H5特有的样式
|
|
24
|
+
/* #ifdef H5 */
|
|
25
|
+
@import './libs/css/style.h5.scss';
|
|
26
|
+
/* #endif */
|
package/index.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
import { configureRuntime, installUIFoundation, runtimeOptionsKey, snake, type RuntimeOptions } from './libs';
|
|
3
|
+
|
|
4
|
+
const SnakeUI = {
|
|
5
|
+
install(app: App, options: RuntimeOptions = {}): void {
|
|
6
|
+
installUIFoundation(app, options);
|
|
7
|
+
const configured = configureRuntime(options);
|
|
8
|
+
app.provide(runtimeOptionsKey, configured);
|
|
9
|
+
(app.config.globalProperties as Record<string, unknown>).$snake = snake;
|
|
10
|
+
if (typeof uni !== 'undefined') {
|
|
11
|
+
(uni as unknown as Record<string, unknown>).$snake = snake;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default SnakeUI;
|
|
17
|
+
|
|
18
|
+
export type { ImageMode, StyleValue } from './types/global';
|
|
19
|
+
export * from './components/snake-activity-list/types';
|
|
20
|
+
export * from './components/snake-auxiliary-segmentation/types';
|
|
21
|
+
export * from './components/snake-button/types';
|
|
22
|
+
export * from './components/snake-loading/types';
|
|
23
|
+
export * from './components/snake-skeleton/types';
|
|
24
|
+
export * from './components/snake-skeleton-item/types';
|
|
25
|
+
export * from './components/snake-transition/types';
|
|
26
|
+
export * from './components/snake-root-portal/types';
|
|
27
|
+
export * from './components/snake-empty/types';
|
|
28
|
+
export * from './components/snake-icon/types';
|
|
29
|
+
export * from './components/snake-image/types';
|
|
30
|
+
export * from './components/snake-qr-code/types';
|
|
31
|
+
export * from './components/snake-loadmore/types';
|
|
32
|
+
export * from './components/snake-notice-bar/types';
|
|
33
|
+
export * from './components/snake-navbar/types';
|
|
34
|
+
export * from './components/snake-overlay/types';
|
|
35
|
+
export * from './components/snake-tooltip/types';
|
|
36
|
+
export * from './components/snake-popup/types';
|
|
37
|
+
export * from './components/snake-sticky/types';
|
|
38
|
+
export * from './components/snake-swiper/types';
|
|
39
|
+
export * from './components/snake-tabs/types';
|
|
40
|
+
export * from './components/snake-tabbar/types';
|
|
41
|
+
export * from './components/snake-upload/types';
|
|
42
|
+
export * from './components/snake-subsection/types';
|
|
43
|
+
export * from './components/snake-button-sort/types';
|
|
44
|
+
export * from './components/snake-drop-menu/types';
|
|
45
|
+
export * from './components/snake-drop-menu-item/types';
|
|
46
|
+
export * from './components/snake-cell-group/types';
|
|
47
|
+
export * from './components/snake-cell-item/types';
|
|
48
|
+
export * from './components/snake-line/types';
|
|
49
|
+
export * from './components/snake-line-progress/types';
|
|
50
|
+
export * from './components/snake-search/types';
|
|
51
|
+
export * from './components/snake-select/types';
|
|
52
|
+
export * from './components/snake-read-more/types';
|
|
53
|
+
export * from './components/snake-no-network/types';
|
|
54
|
+
export * from './components/snake-link/types';
|
|
55
|
+
export * from './components/snake-text/types';
|
|
56
|
+
export * from './components/snake-calendar/types';
|
|
57
|
+
export * from './components/snake-index-list/types';
|
|
58
|
+
export * from './components/snake-index-list-panel/types';
|
|
59
|
+
export * from './components/snake-index-anchor/types';
|
|
60
|
+
export * from './components/snake-form/types';
|
|
61
|
+
export * from './components/snake-form-item/types';
|
|
62
|
+
export * from './components/snake-input/types';
|
|
63
|
+
export * from './components/snake-textarea/types';
|
|
64
|
+
export * from './components/snake-checkbox/types';
|
|
65
|
+
export * from './components/snake-checkbox-group/types';
|
|
66
|
+
export * from './components/snake-count-down/types';
|
|
67
|
+
export * from './components/snake-radio/types';
|
|
68
|
+
export * from './components/snake-radio-group/types';
|
|
69
|
+
export * from './components/snake-switch/types';
|
|
70
|
+
export * from './components/snake-slider/types';
|
|
71
|
+
export * from './components/snake-cms/types';
|
|
72
|
+
export * from './components/snake-config-provider/types';
|
|
73
|
+
export * from './components/snake-commodity-search/types';
|
|
74
|
+
export * from './components/snake-coupon/types';
|
|
75
|
+
export * from './components/snake-custom-module/types';
|
|
76
|
+
export * from './components/snake-filter-sorts/types';
|
|
77
|
+
export * from './components/snake-follow/types';
|
|
78
|
+
export * from './components/snake-goods-list/types';
|
|
79
|
+
export * from './components/snake-graphic-navigation/types';
|
|
80
|
+
export * from './components/snake-images/types';
|
|
81
|
+
export * from './components/snake-jump-applet/types';
|
|
82
|
+
export * from './components/snake-list-switching/types';
|
|
83
|
+
export * from './components/snake-magic-cube/types';
|
|
84
|
+
export * from './components/snake-modal/types';
|
|
85
|
+
export * from './components/snake-toast/types';
|
|
86
|
+
export * from './components/snake-notice/types';
|
|
87
|
+
export * from './components/snake-page-popup/types';
|
|
88
|
+
export * from './components/snake-picture-ads/types';
|
|
89
|
+
export * from './components/snake-rich-text/types';
|
|
90
|
+
export * from './components/snake-parse/types';
|
|
91
|
+
export * from './components/snake-floating-bubble/types';
|
|
92
|
+
export * from './components/snake-videos/types';
|
|
93
|
+
export * from './libs';
|
|
94
|
+
export * from './locale';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export type CmsBlockCategory = 'content' | 'navigation' | 'commerce' | 'custom';
|
|
2
|
+
|
|
3
|
+
export interface CmsBlockDefinition {
|
|
4
|
+
version: 1 | 2;
|
|
5
|
+
category: CmsBlockCategory;
|
|
6
|
+
componentName: `snake-${string}`;
|
|
7
|
+
standalone: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Built-in page-decoration blocks supported by snake-cms.
|
|
12
|
+
*
|
|
13
|
+
* Keep this catalog free of Vue imports so it can be consumed by types,
|
|
14
|
+
* diagnostics and tooling without changing mini-program bundling behavior.
|
|
15
|
+
*/
|
|
16
|
+
export const cmsBlocks = {
|
|
17
|
+
commoditysearch: {
|
|
18
|
+
version: 1,
|
|
19
|
+
category: 'navigation',
|
|
20
|
+
componentName: 'snake-commodity-search',
|
|
21
|
+
standalone: true
|
|
22
|
+
},
|
|
23
|
+
auxiliarysegmentation: {
|
|
24
|
+
version: 1,
|
|
25
|
+
category: 'content',
|
|
26
|
+
componentName: 'snake-auxiliary-segmentation',
|
|
27
|
+
standalone: true
|
|
28
|
+
},
|
|
29
|
+
richtext: { version: 1, category: 'content', componentName: 'snake-rich-text', standalone: true },
|
|
30
|
+
graphicnavigation: {
|
|
31
|
+
version: 1,
|
|
32
|
+
category: 'navigation',
|
|
33
|
+
componentName: 'snake-graphic-navigation',
|
|
34
|
+
standalone: true
|
|
35
|
+
},
|
|
36
|
+
images: { version: 1, category: 'content', componentName: 'snake-images', standalone: true },
|
|
37
|
+
pictureads: { version: 1, category: 'content', componentName: 'snake-picture-ads', standalone: true },
|
|
38
|
+
magiccube: { version: 1, category: 'content', componentName: 'snake-magic-cube', standalone: true },
|
|
39
|
+
videos: { version: 1, category: 'content', componentName: 'snake-videos', standalone: true },
|
|
40
|
+
notice: { version: 1, category: 'content', componentName: 'snake-notice', standalone: true },
|
|
41
|
+
jumpApplet: { version: 1, category: 'navigation', componentName: 'snake-jump-applet', standalone: true },
|
|
42
|
+
follow: { version: 1, category: 'navigation', componentName: 'snake-follow', standalone: true },
|
|
43
|
+
suspension: {
|
|
44
|
+
version: 1,
|
|
45
|
+
category: 'navigation',
|
|
46
|
+
componentName: 'snake-floating-bubble',
|
|
47
|
+
standalone: true
|
|
48
|
+
},
|
|
49
|
+
coupon: { version: 1, category: 'commerce', componentName: 'snake-coupon', standalone: true },
|
|
50
|
+
pagePopup: { version: 1, category: 'navigation', componentName: 'snake-page-popup', standalone: true },
|
|
51
|
+
goodslist: { version: 1, category: 'commerce', componentName: 'snake-goods-list', standalone: true },
|
|
52
|
+
custommodule: { version: 1, category: 'custom', componentName: 'snake-custom-module', standalone: true },
|
|
53
|
+
'v2.carousel': { version: 2, category: 'content', componentName: 'snake-cms-v2-carousel', standalone: false },
|
|
54
|
+
'v2.coupon': { version: 2, category: 'commerce', componentName: 'snake-cms-v2-coupon', standalone: false },
|
|
55
|
+
'v2.custom': { version: 2, category: 'custom', componentName: 'snake-cms-v2-custom', standalone: false },
|
|
56
|
+
'v2.divider': { version: 2, category: 'content', componentName: 'snake-cms-v2-divider', standalone: false },
|
|
57
|
+
'v2.floatbutton': {
|
|
58
|
+
version: 2,
|
|
59
|
+
category: 'navigation',
|
|
60
|
+
componentName: 'snake-cms-v2-floatbutton',
|
|
61
|
+
standalone: false
|
|
62
|
+
},
|
|
63
|
+
'v2.goodslist': {
|
|
64
|
+
version: 2,
|
|
65
|
+
category: 'commerce',
|
|
66
|
+
componentName: 'snake-cms-v2-goods-list',
|
|
67
|
+
standalone: false
|
|
68
|
+
},
|
|
69
|
+
'v2.hotzone': { version: 2, category: 'navigation', componentName: 'snake-cms-v2-hotzone', standalone: false },
|
|
70
|
+
'v2.images': { version: 2, category: 'content', componentName: 'snake-cms-v2-images', standalone: false },
|
|
71
|
+
'v2.magiccube': {
|
|
72
|
+
version: 2,
|
|
73
|
+
category: 'content',
|
|
74
|
+
componentName: 'snake-cms-v2-magiccube',
|
|
75
|
+
standalone: false
|
|
76
|
+
},
|
|
77
|
+
'v2.notice': { version: 2, category: 'content', componentName: 'snake-cms-v2-notice', standalone: false },
|
|
78
|
+
'v2.popup': { version: 2, category: 'navigation', componentName: 'snake-cms-v2-popup', standalone: false },
|
|
79
|
+
'v2.richtext': {
|
|
80
|
+
version: 2,
|
|
81
|
+
category: 'content',
|
|
82
|
+
componentName: 'snake-cms-v2-richtext',
|
|
83
|
+
standalone: false
|
|
84
|
+
},
|
|
85
|
+
'v2.search': { version: 2, category: 'navigation', componentName: 'snake-cms-v2-search', standalone: false },
|
|
86
|
+
'v2.video': { version: 2, category: 'content', componentName: 'snake-cms-v2-video', standalone: false }
|
|
87
|
+
} as const satisfies Record<string, CmsBlockDefinition>;
|
|
88
|
+
|
|
89
|
+
export type CmsBuiltinComponent = keyof typeof cmsBlocks;
|
|
90
|
+
export type CmsV1BuiltinComponent = {
|
|
91
|
+
[Key in CmsBuiltinComponent]: (typeof cmsBlocks)[Key]['version'] extends 1 ? Key : never;
|
|
92
|
+
}[CmsBuiltinComponent];
|
|
93
|
+
export type CmsV2BuiltinComponent = {
|
|
94
|
+
[Key in CmsBuiltinComponent]: (typeof cmsBlocks)[Key]['version'] extends 2 ? Key : never;
|
|
95
|
+
}[CmsBuiltinComponent];
|
|
96
|
+
|
|
97
|
+
export const cmsBuiltinComponents = new Set<CmsBuiltinComponent>(
|
|
98
|
+
Object.keys(cmsBlocks) as CmsBuiltinComponent[]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
export function isCmsBuiltinComponent(component: string): component is CmsBuiltinComponent {
|
|
102
|
+
return cmsBuiltinComponents.has(component as CmsBuiltinComponent);
|
|
103
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { deepMerge } from '../function';
|
|
2
|
+
import type { CmsOptions } from './types';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_CMS_OPTIONS: CmsOptions = {
|
|
5
|
+
aliases: { videoss: 'videos' },
|
|
6
|
+
normalizers: {},
|
|
7
|
+
services: {},
|
|
8
|
+
assets: {},
|
|
9
|
+
cachePrefix: 'snake-ui:cms'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
let globalCmsOptions: CmsOptions = deepMerge(DEFAULT_CMS_OPTIONS, {});
|
|
13
|
+
|
|
14
|
+
export function configureCms(options?: CmsOptions): CmsOptions {
|
|
15
|
+
globalCmsOptions = deepMerge(globalCmsOptions, options || {});
|
|
16
|
+
return globalCmsOptions;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getCmsOptions(instance?: CmsOptions): CmsOptions {
|
|
20
|
+
return deepMerge(globalCmsOptions, instance || {});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function resetCmsOptions(): void {
|
|
24
|
+
globalCmsOptions = deepMerge(DEFAULT_CMS_OPTIONS, {});
|
|
25
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { deepClone } from '../function';
|
|
2
|
+
import { isCmsBuiltinComponent, cmsBlocks } from './blocks';
|
|
3
|
+
export { cmsBuiltinComponents } from './blocks';
|
|
4
|
+
import type {
|
|
5
|
+
CmsBuiltinComponent,
|
|
6
|
+
CmsComponentConfig,
|
|
7
|
+
CmsDiagnostic,
|
|
8
|
+
CmsNormalizedComponent,
|
|
9
|
+
CmsOptions,
|
|
10
|
+
CmsPageInfo
|
|
11
|
+
} from './types';
|
|
12
|
+
import type { CmsV2BuiltinComponent } from './blocks';
|
|
13
|
+
import { normalizeCmsV2Props } from './v2';
|
|
14
|
+
|
|
15
|
+
export interface CmsNormalizeResult {
|
|
16
|
+
components: CmsNormalizedComponent[];
|
|
17
|
+
diagnostics: CmsDiagnostic[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function normalizeCmsComponents(
|
|
21
|
+
input: unknown,
|
|
22
|
+
pageInfo: CmsPageInfo = {},
|
|
23
|
+
options: CmsOptions = {}
|
|
24
|
+
): CmsNormalizeResult {
|
|
25
|
+
const diagnostics: CmsDiagnostic[] = [];
|
|
26
|
+
const components: CmsNormalizedComponent[] = [];
|
|
27
|
+
const aliases: Record<string, CmsBuiltinComponent> = { videoss: 'videos', ...(options.aliases || {}) };
|
|
28
|
+
let hasCommerceSection = false;
|
|
29
|
+
|
|
30
|
+
if (!Array.isArray(input)) {
|
|
31
|
+
diagnostics.push({ code: 'invalid-component', level: 'error', message: 'pageComponents must be an array.' });
|
|
32
|
+
return { components, diagnostics };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
input.forEach((raw, index) => {
|
|
36
|
+
if (!raw || typeof raw !== 'object' || typeof (raw as CmsComponentConfig).component !== 'string') {
|
|
37
|
+
diagnostics.push({
|
|
38
|
+
code: 'invalid-component',
|
|
39
|
+
level: 'error',
|
|
40
|
+
index,
|
|
41
|
+
message: 'CMS component must contain a string component key.'
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let item = deepClone(raw as CmsComponentConfig);
|
|
47
|
+
const originalComponent = item.component;
|
|
48
|
+
const normalizer = options.normalizers?.[originalComponent];
|
|
49
|
+
if (normalizer) {
|
|
50
|
+
try {
|
|
51
|
+
const normalized = normalizer(item, { index, pageInfo });
|
|
52
|
+
if (!normalized) return;
|
|
53
|
+
item = normalized;
|
|
54
|
+
} catch (cause) {
|
|
55
|
+
diagnostics.push({
|
|
56
|
+
code: 'normalizer-error',
|
|
57
|
+
level: 'error',
|
|
58
|
+
index,
|
|
59
|
+
component: originalComponent,
|
|
60
|
+
message: `Normalizer failed for "${originalComponent}".`,
|
|
61
|
+
cause
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// alias 只改变实际渲染组件;originalComponent 保留原始下发键,供 normalizer 与诊断追溯来源。
|
|
68
|
+
const component = aliases[item.component] || item.component;
|
|
69
|
+
const version = item.component.startsWith('v2.') ? 2 : 1;
|
|
70
|
+
const setStyle = item.setStyle && typeof item.setStyle === 'object' ? item.setStyle : {};
|
|
71
|
+
const hasValidV2Props = item.props !== null && typeof item.props === 'object' && !Array.isArray(item.props);
|
|
72
|
+
let componentProps = hasValidV2Props ? item.props || {} : {};
|
|
73
|
+
if (version === 1 && (item.visible === false || setStyle.showComponent === false)) return;
|
|
74
|
+
if (version === 2 && item.active === false) return;
|
|
75
|
+
|
|
76
|
+
const builtin = isCmsBuiltinComponent(component);
|
|
77
|
+
if (version === 2 && !hasValidV2Props) {
|
|
78
|
+
diagnostics.push({
|
|
79
|
+
code: 'invalid-component',
|
|
80
|
+
level: 'error',
|
|
81
|
+
index,
|
|
82
|
+
component,
|
|
83
|
+
message: `CMS v2 component "${component}" must contain an object props field.`
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (builtin && cmsBlocks[component].version !== version) {
|
|
87
|
+
diagnostics.push({
|
|
88
|
+
code: 'invalid-component',
|
|
89
|
+
level: 'error',
|
|
90
|
+
index,
|
|
91
|
+
component,
|
|
92
|
+
message: `CMS component "${component}" has an invalid protocol version.`
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (builtin && version === 2 && cmsBlocks[component].version === 2) {
|
|
96
|
+
componentProps = normalizeCmsV2Props(component as CmsV2BuiltinComponent, componentProps);
|
|
97
|
+
}
|
|
98
|
+
if (component === 'goodslist' || component === 'v2.goodslist') {
|
|
99
|
+
if (hasCommerceSection) {
|
|
100
|
+
diagnostics.push({
|
|
101
|
+
code: 'duplicate-commerce-section',
|
|
102
|
+
level: 'warn',
|
|
103
|
+
index,
|
|
104
|
+
component,
|
|
105
|
+
message: 'Only the first goodslist section is rendered.'
|
|
106
|
+
});
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
hasCommerceSection = true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!builtin) {
|
|
113
|
+
diagnostics.push({
|
|
114
|
+
code: 'unknown-component',
|
|
115
|
+
level: 'warn',
|
|
116
|
+
index,
|
|
117
|
+
component,
|
|
118
|
+
message: `Unknown CMS component "${component}".`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
components.push({
|
|
123
|
+
...item,
|
|
124
|
+
id: String(item.id ?? `${component}-${index}`),
|
|
125
|
+
component,
|
|
126
|
+
version,
|
|
127
|
+
originalComponent,
|
|
128
|
+
setStyle,
|
|
129
|
+
props: componentProps,
|
|
130
|
+
builtin
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return { components, diagnostics };
|
|
135
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isDebugMode } from '../config/state';
|
|
2
|
+
import type { CmsDiagnostic, CmsOptions } from './types';
|
|
3
|
+
import { getCmsOptions } from './config';
|
|
4
|
+
|
|
5
|
+
export function reportCmsDiagnostic(options: CmsOptions, diagnostic: CmsDiagnostic): void {
|
|
6
|
+
options.onDiagnostic?.(diagnostic);
|
|
7
|
+
if (isDebugMode('warn')) console.warn(`[Snake UI CMS] ${diagnostic.message}`, diagnostic);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function resolveCmsOptions(instance?: CmsOptions): CmsOptions {
|
|
11
|
+
return getCmsOptions(instance);
|
|
12
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { CmsBuiltinComponent } from './blocks';
|
|
2
|
+
|
|
3
|
+
export type {
|
|
4
|
+
CmsBlockCategory,
|
|
5
|
+
CmsBlockDefinition,
|
|
6
|
+
CmsBuiltinComponent,
|
|
7
|
+
CmsV1BuiltinComponent,
|
|
8
|
+
CmsV2BuiltinComponent
|
|
9
|
+
} from './blocks';
|
|
10
|
+
|
|
11
|
+
export interface CmsPageInfo {
|
|
12
|
+
id?: string | number;
|
|
13
|
+
pageId?: string | number;
|
|
14
|
+
name?: string;
|
|
15
|
+
activityId?: string | number;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CmsComponentConfig<Style extends Record<string, any> = Record<string, any>> {
|
|
20
|
+
id?: string | number;
|
|
21
|
+
component: string;
|
|
22
|
+
setStyle?: Style;
|
|
23
|
+
props?: Record<string, any>;
|
|
24
|
+
active?: boolean;
|
|
25
|
+
visible?: boolean;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CmsNormalizedComponent<Style extends Record<string, any> = Record<string, any>> extends Omit<
|
|
30
|
+
CmsComponentConfig<Style>,
|
|
31
|
+
'id' | 'setStyle'
|
|
32
|
+
> {
|
|
33
|
+
id: string;
|
|
34
|
+
version: 1 | 2;
|
|
35
|
+
originalComponent: string;
|
|
36
|
+
setStyle: Style;
|
|
37
|
+
props: Record<string, any>;
|
|
38
|
+
builtin: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type CmsDiagnosticCode =
|
|
42
|
+
'invalid-component' | 'unknown-component' | 'normalizer-error' | 'duplicate-commerce-section';
|
|
43
|
+
|
|
44
|
+
export interface CmsDiagnostic {
|
|
45
|
+
code: CmsDiagnosticCode;
|
|
46
|
+
level: 'warn' | 'error';
|
|
47
|
+
message: string;
|
|
48
|
+
index?: number;
|
|
49
|
+
component?: string;
|
|
50
|
+
cause?: unknown;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type CmsStatus = 'idle' | 'initial-loading' | 'ready' | 'empty' | 'loading-more' | 'no-more' | 'error';
|
|
54
|
+
|
|
55
|
+
/** CmsStateChange 类型定义。 */
|
|
56
|
+
export interface CmsStateChange {
|
|
57
|
+
/** 当前状态。 */
|
|
58
|
+
status: CmsStatus;
|
|
59
|
+
/** page 配置。 */
|
|
60
|
+
page: number;
|
|
61
|
+
/** item count 配置。 */
|
|
62
|
+
itemCount: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface CmsServiceContext {
|
|
66
|
+
pageInfo: Readonly<CmsPageInfo>;
|
|
67
|
+
component: Readonly<CmsNormalizedComponent>;
|
|
68
|
+
generation: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface CmsActivityResult<Item = Record<string, any>> {
|
|
72
|
+
items: Item[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface CmsGoodsResult<Item = Record<string, any>> {
|
|
76
|
+
items: Item[];
|
|
77
|
+
total?: number;
|
|
78
|
+
hasMore?: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface CmsCommerceService<
|
|
82
|
+
Activity = Record<string, any>,
|
|
83
|
+
Filters = Record<string, any>,
|
|
84
|
+
Goods = Record<string, any>
|
|
85
|
+
> {
|
|
86
|
+
getActivities?(
|
|
87
|
+
context: CmsServiceContext & { params: Record<string, unknown> }
|
|
88
|
+
): Promise<CmsActivityResult<Activity>>;
|
|
89
|
+
getFilters?(context: CmsServiceContext & { params: Record<string, unknown> }): Promise<Filters>;
|
|
90
|
+
getGoods(context: CmsServiceContext & { params: Record<string, unknown> }): Promise<CmsGoodsResult<Goods>>;
|
|
91
|
+
navigateGoods?(context: CmsServiceContext & { item: Goods; index: number }): void | Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface CmsCouponService {
|
|
95
|
+
check(context: {
|
|
96
|
+
config: Record<string, any>;
|
|
97
|
+
pageInfo?: CmsPageInfo;
|
|
98
|
+
}): Promise<{ claimable: boolean; message?: string }>;
|
|
99
|
+
receive(context: {
|
|
100
|
+
config: Record<string, any>;
|
|
101
|
+
pageInfo?: CmsPageInfo;
|
|
102
|
+
}): Promise<{ success: boolean; message?: string }>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface CmsLinkAction {
|
|
106
|
+
type: 'navigate' | 'mini-program' | 'external' | 'scheme';
|
|
107
|
+
url?: string;
|
|
108
|
+
appId?: string;
|
|
109
|
+
path?: string;
|
|
110
|
+
extraData?: Record<string, unknown>;
|
|
111
|
+
envVersion?: 'develop' | 'trial' | 'release';
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface CmsLinkService {
|
|
116
|
+
open(
|
|
117
|
+
action: CmsLinkAction,
|
|
118
|
+
context?: { component?: CmsNormalizedComponent; pageInfo?: CmsPageInfo }
|
|
119
|
+
): void | Promise<void>;
|
|
120
|
+
createScheme?(action: CmsLinkAction): Promise<string>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface CmsServices {
|
|
124
|
+
commerce?: CmsCommerceService;
|
|
125
|
+
coupon?: CmsCouponService;
|
|
126
|
+
link?: CmsLinkService;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface CmsAssets {
|
|
130
|
+
backToTop?: string;
|
|
131
|
+
activityAll?: string;
|
|
132
|
+
goodsLoading?: string;
|
|
133
|
+
goodsError?: string;
|
|
134
|
+
goodsSoldOut?: string;
|
|
135
|
+
goodsInspection?: string;
|
|
136
|
+
goodsNewcomer?: string;
|
|
137
|
+
goodsPopular?: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type CmsNormalizer = (
|
|
141
|
+
component: CmsComponentConfig,
|
|
142
|
+
context: { index: number; pageInfo: Readonly<CmsPageInfo> }
|
|
143
|
+
) => CmsComponentConfig | null | undefined;
|
|
144
|
+
|
|
145
|
+
export interface CmsOptions {
|
|
146
|
+
aliases?: Record<string, CmsBuiltinComponent>;
|
|
147
|
+
normalizers?: Record<string, CmsNormalizer>;
|
|
148
|
+
services?: CmsServices;
|
|
149
|
+
assets?: CmsAssets;
|
|
150
|
+
cachePrefix?: string;
|
|
151
|
+
onDiagnostic?: (diagnostic: CmsDiagnostic) => void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export class CmsError extends Error {
|
|
155
|
+
readonly stage: 'normalize' | 'activities' | 'filters' | 'goods' | 'coupon' | 'link';
|
|
156
|
+
readonly cause?: unknown;
|
|
157
|
+
|
|
158
|
+
constructor(stage: CmsError['stage'], message: string, cause?: unknown) {
|
|
159
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
160
|
+
this.name = 'CmsError';
|
|
161
|
+
this.stage = stage;
|
|
162
|
+
this.cause = cause;
|
|
163
|
+
}
|
|
164
|
+
}
|