diff --git a/packages/duoyun-ui/docs/en/01-guide/03-customize.md b/packages/duoyun-ui/docs/en/01-guide/03-customize.md index 582a9456..7e1393e1 100644 --- a/packages/duoyun-ui/docs/en/01-guide/03-customize.md +++ b/packages/duoyun-ui/docs/en/01-guide/03-customize.md @@ -50,7 +50,7 @@ Extend theme: ```ts import { extendTheme } from 'duoyun-ui/lib/theme'; -export const theme = extendTheme({ myColor: '#f00' }); +export const [theme, updateTheme] = extendTheme({ myColor: '#f00' }); ``` ## Customize icon @@ -60,7 +60,7 @@ Currently DuoyunUI uses [Material Icon](https://fonts.google.com/icons?selected= ```ts import { extendIcons } from 'duoyun-ui/lib/icons'; -const icons = extendIcons({ +const [icons, updateIcons] = extendIcons({ more: `
${internals.map((item) => this.renderInternalItem(item))} diff --git a/packages/gem-book/src/element/elements/sidebar.ts b/packages/gem-book/src/element/elements/sidebar.ts index fd6f637b..890a4f41 100644 --- a/packages/gem-book/src/element/elements/sidebar.ts +++ b/packages/gem-book/src/element/elements/sidebar.ts @@ -6,11 +6,9 @@ import { connectStore, classMap, state, - createStore, connect, - updateStore, history, - disconnect, + useStore, } from '@mantou/gem'; import { mediaQuery } from '@mantou/gem/helper/mediaquery'; @@ -26,10 +24,7 @@ import '@mantou/gem/elements/use'; import './side-link'; import './nav-logo'; -export const sidebarStore = createStore({ open: false }); - -const closeSidebar = () => updateStore(sidebarStore, { open: false }); -export const toggleSidebar = () => updateStore(sidebarStore, { open: !sidebarStore.open }); +export const [sidebarStore, updateSidebarStore] = useStore({ open: false }); @customElement('gem-book-sidebar') @connectStore(bookStore) @@ -219,7 +214,7 @@ export class SideBar extends GemElement { position: fixed; background: ${theme.backgroundColor}; width: 100%; - height: calc(100vh - ${theme.headerHeight}); + height: calc(100dvh - ${theme.headerHeight}); top: ${theme.headerHeight}; z-index: 3; } @@ -267,7 +262,6 @@ export class SideBar extends GemElement { } mounted() { - connect(history.store, closeSidebar); - return () => disconnect(history.store, closeSidebar); + return connect(history.store, () => updateSidebarStore({ open: false })); } } diff --git a/packages/gem-book/src/element/elements/toc.ts b/packages/gem-book/src/element/elements/toc.ts index 5d250933..caabb19f 100644 --- a/packages/gem-book/src/element/elements/toc.ts +++ b/packages/gem-book/src/element/elements/toc.ts @@ -6,15 +6,15 @@ import { createCSSSheet, css, connectStore, - createStore, classMap, + useStore, } from '@mantou/gem'; import { theme, themeStore } from '../helper/theme'; import '@mantou/gem/elements/link'; -export const tocStore = createStore<{ elements: HTMLHeadingElement[] }>({ +export const [tocStore, updateTocStore] = useStore<{ elements: HTMLHeadingElement[] }>({ elements: [], }); diff --git a/packages/gem-book/src/element/store.ts b/packages/gem-book/src/element/store.ts index 6972cd77..1ac2d3b2 100644 --- a/packages/gem-book/src/element/store.ts +++ b/packages/gem-book/src/element/store.ts @@ -1,4 +1,4 @@ -import { connect, createStore, html, updateStore, history } from '@mantou/gem'; +import { connect, html, history, useStore } from '@mantou/gem'; import { RouteItem, GemLightRouteElement } from '@mantou/gem/elements/route'; import { I18n } from '@mantou/gem/helper/i18n'; @@ -31,7 +31,7 @@ interface CurrentBookConfig { isDevMode: () => boolean; } -export const bookStore = createStore>({}); +export const [bookStore, updateBookStore] = useStore>({}); function getI18nSidebar(config: BookConfig | undefined) { let sidebar: NavItem[] = []; @@ -238,7 +238,7 @@ export function updateBookConfig(config?: BookConfig, gemBookElement?: GemBookEl const currentLinks = flatNav(currentSidebar).filter( (e) => !e.sidebarIgnore && (!config?.homeMode || e.link !== homePage), ); - updateStore(bookStore, { + updateBookStore({ config, links, nav, @@ -251,7 +251,7 @@ export function updateBookConfig(config?: BookConfig, gemBookElement?: GemBookEl currentLinks, }); if (gemBookElement) { - updateStore(bookStore, { + updateBookStore({ isDevMode: () => gemBookElement.dev, getCurrentLink: () => { return gemBookElement?.routeRef.element?.currentRoute?.data as NavItemWithLink; diff --git a/packages/gem-devtools/src/store.ts b/packages/gem-devtools/src/store.ts index 4d6332a5..2fd54842 100644 --- a/packages/gem-devtools/src/store.ts +++ b/packages/gem-devtools/src/store.ts @@ -1,4 +1,4 @@ -import { createStore, updateStore } from '@mantou/gem'; +import { useStore } from '@mantou/gem'; const types = typeof ('' as any); type Type = typeof types | 'element' | 'null'; @@ -43,19 +43,11 @@ export class PanelStore { staticMember = new Array(); } -export const panelStore = createStore({ ...new PanelStore(), isGemElement: false }); +export const [panelStore, changePanelStore] = useStore({ ...new PanelStore(), isGemElement: false }); export class ConfigureStore { currentFrameURL = ''; frames: string[] = []; } -export const configureStore = createStore(new ConfigureStore()); - -export function changePanelStore(newPanelData: PanelStore) { - updateStore(panelStore, newPanelData); -} - -export function changeConfigureStore(data: Partial) { - updateStore(configureStore, data); -} +export const [configureStore, changeConfigureStore] = useStore(new ConfigureStore()); diff --git a/packages/gem-examples/src/cascader/index.ts b/packages/gem-examples/src/cascader/index.ts index 3083bc0c..13b180a3 100644 --- a/packages/gem-examples/src/cascader/index.ts +++ b/packages/gem-examples/src/cascader/index.ts @@ -1,4 +1,4 @@ -import { connect, createStore, html, render, updateStore } from '@mantou/gem'; +import { connect, html, render, useStore } from '@mantou/gem'; import type { Option } from 'duoyun-ui/elements/cascader-picker'; import { sleep } from 'duoyun-ui/lib/utils'; @@ -7,7 +7,7 @@ import 'duoyun-ui/elements/loading'; import '../elements/layout'; -const store = createStore({ +const [store, update] = useStore({ selected: [['Item 3', 'Item 3.3', 'Item 3.3.1']], options: [ { label: 'Item 1' }, @@ -29,7 +29,7 @@ const store = createStore({ }); function onChange({ detail }: CustomEvent) { - updateStore(store, { selected: detail }); + update({ selected: detail }); } async function onExpand({ detail }: CustomEvent