Skip to content

Commit 308949b

Browse files
committedAug 11, 2024·
Update docs
1 parent 5e27af7 commit 308949b

33 files changed

+958
-144
lines changed
 

‎.prettierrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
"files": ["*.md"],
1010
"options": {
11-
"printWidth": 80
11+
"printWidth": 100
1212
}
1313
}
1414
]
+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
---
2+
isNav: true
3+
---
4+
5+
# Plugins
6+
7+
## `<gbp-code-group>`
8+
9+
Used to display several pieces of code with similar functionality:
10+
11+
<gbp-code-group>
12+
13+
```bash npm
14+
npm i gem-book
15+
```
16+
17+
```bash yarn
18+
yarn add gem-book
19+
```
20+
21+
</gbp-code-group>
22+
23+
````md
24+
<gbp-code-group>
25+
26+
```bash npm
27+
npm i gem-book
28+
```
29+
30+
```bash yarn
31+
yarn add gem-book
32+
```
33+
34+
</gbp-code-group>
35+
````
36+
37+
## `<gbp-raw>`
38+
39+
Used to display remote code. If the provided `src` only contains a path, it will read content from the current project's GitHub (affected by [`sourceDir`](./002-cli.md#--source-dir) and [`sourceBranch`](./002-cli.md#--source-branch)), for example:
40+
41+
<gbp-raw src="package.json" range="2-3,-4--6,author-license" highlight="-5,author"></gbp-raw>
42+
43+
```md
44+
<!-- `range` specifies the display range, supporting negative numbers and string matching, `highlight` format is the same -->
45+
46+
<gbp-raw src="package.json" range="2-3,-4--6,author-license" highlight="-5,author"></gbp-raw>
47+
```
48+
49+
## `<gbp-var>`
50+
51+
Reference global variable: <gbp-var>hello</gbp-var>
52+
53+
```md
54+
<gbp-var>hello</gbp-var>
55+
```
56+
57+
The variable needs to be defined in the [configuration file](./002-cli.md).
58+
59+
## `<gbp-media>`
60+
61+
Displays remote multimedia content, such as images or videos, using the same resource retrieval method as `<gbp-raw>`:
62+
63+
```md
64+
<gbp-media src="preview.png"></gbp-media>
65+
```
66+
67+
## `<gbp-include>`
68+
69+
Dynamically loads Markdown snippets:
70+
71+
<gbp-include src="./guide/007-extension.md" range="[!NOTE]->"></gbp-include>
72+
73+
```md
74+
<!-- `range` syntax is the same as `<gbp-raw>`, here `range` uses string matching -->
75+
76+
<gbp-include src="./guide/007-extension.md" range="[!NOTE]->"></gbp-include>
77+
```
78+
79+
## `<gbp-import>`
80+
81+
Dynamically imports modules, which can be used to load plugins on demand. For example, the following custom element is dynamically loaded (the `.ts` file will be compiled using [esm.sh](https://esm.sh/)):
82+
83+
<gbp-import src="docs/hello.ts"></gbp-import>
84+
85+
<my-plugin-hello></my-plugin-hello>
86+
87+
```md
88+
<gbp-import src="docs/hello.ts"></gbp-import>
89+
90+
<my-plugin-hello></my-plugin-hello>
91+
```
92+
93+
## `<gbp-content>`
94+
95+
Insert content into `<gem-book>`, allowing customization of `<gem-book>` content on specific pages, such as a custom sidebar:
96+
97+
```md
98+
<gbp-content slot="sidebar-before">
99+
<div>Test</div>
100+
<style>
101+
gem-book [part=sidebar-content] {
102+
display: none;
103+
}
104+
</style>
105+
</gbp-content>
106+
```
107+
108+
## `<gbp-docsearch>`
109+
110+
Use [Algolia DocSearch](https://docsearch.algolia.com/) to provide search for the website, instantiated only once, and can be placed using [slots](./guide/007-extension.md#slots):
111+
112+
<gbp-raw src="docs/template.html" range="13--4"></gbp-raw>
113+
114+
> [!WARNING]
115+
>
116+
> `renderJavaScript` must be enabled in the [configuration](https://crawler.algolia.com/admin/crawlers) for Algolia DocSearch Crawler.
117+
118+
Using `docsearch?local` can provide local search service (thanks to [MiniSearch](https://github.com/lucaong/minisearch/)), [example](https://duoyun-ui.gemjs.org).
119+
120+
## `<gbp-comment>`
121+
122+
It uses [Gitalk](https://github.com/gitalk/gitalk) to bring comment functionality to the website, similar to the usage of `<gbp-docsearch>`:
123+
124+
```html
125+
<gem-book>
126+
<gbp-comment
127+
slot="main-after"
128+
client-id="xxx"
129+
client-secret="xxx"
130+
></gbp-comment>
131+
</gem-book>
132+
```
133+
134+
## `<gbp-sandpack>`
135+
136+
Use [Sandpack](https://sandpack.codesandbox.io/) to create interactive examples:
137+
138+
<gbp-sandpack dependencies="@mantou/gem, duoyun-ui">
139+
140+
```ts
141+
import { render, html } from '@mantou/gem';
142+
143+
import 'duoyun-ui/elements/button';
144+
145+
render(
146+
html`<dy-button>Time: ${new Date().toLocaleString()}</dy-button>`,
147+
document.getElementById('root'),
148+
);
149+
```
150+
151+
</gbp-sandpack>
152+
153+
````md
154+
<gbp-sandpack dependencies="@mantou/gem, duoyun-ui">
155+
156+
```ts
157+
import { render, html } from '@mantou/gem';
158+
159+
import 'duoyun-ui/elements/button';
160+
161+
render(
162+
html`<dy-button>Time: ${new Date().toLocaleString()}</dy-button>`,
163+
document.getElementById('root'),
164+
);
165+
```
166+
167+
</gbp-sandpack>
168+
````
169+
170+
## `<gbp-example>`
171+
172+
Generate examples for any custom element, for example:
173+
174+
<gbp-example name="dy-avatar" src="https://esm.sh/duoyun-ui/elements/avatar">
175+
176+
```json
177+
{
178+
"src": "https://api.dicebear.com/5.x/bottts-neutral/svg",
179+
"status": "positive",
180+
"size": "large",
181+
"square": true
182+
}
183+
```
184+
185+
</gbp-example>
186+
187+
````md
188+
<gbp-example name="dy-avatar" src="https://esm.sh/duoyun-ui/elements/avatar">
189+
190+
```json
191+
{
192+
"src": "https://api.dicebear.com/5.x/bottts-neutral/svg",
193+
"status": "positive",
194+
"size": "large",
195+
"square": true
196+
}
197+
```
198+
199+
</gbp-example>
200+
````
201+
202+
## `<gbp-api>`
203+
204+
Use [`gem-analyzer`](https://github.com/mantou132/gem/blob/main/packages/gem-analyzer) to generate API documentation for `GemElement`, such as [GemBookElement API](./004-api.md);

‎packages/gem-devtools/src/scripts/get-gem.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const getSelectedGem = function (data: PanelStore): PanelStore | string {
1010
if (!$0) return `Not Gem: $0 is ${$0}`;
1111
const { __GEM_DEVTOOLS__HOOK__ } = window;
1212
if (__GEM_DEVTOOLS__HOOK__) {
13+
// 不支持多种 GemElement,__GEM_DEVTOOLS__HOOK__ 只记录首个
1314
const { GemElement } = __GEM_DEVTOOLS__HOOK__;
1415
if (!GemElement || !($0 instanceof GemElement)) return 'Not Gem: gem hook';
1516
} else {

‎packages/gem-devtools/src/sidebarpanel.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async function updateElementProperties() {
1616
if (typeof result !== 'string') {
1717
changePanelStore(result);
1818
} else {
19+
logger.info(result);
1920
changePanelStore(await execution(getDomStat, [new PanelStore({ isGemElement: false })]));
2021
}
2122
} catch (err) {

‎packages/gem-examples/src/scope/index.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ const closedStyles = createCSSSheet(css`
99
`);
1010
@shadow({ mode: 'closed' })
1111
@adoptedStyle(closedStyles)
12-
@customElement('app-closed')
12+
@customElement('closed-shadow-dom')
1313
class _Closed extends GemElement {
1414
render() {
1515
return html`<div>Closed shadow</div>`;
1616
}
1717
}
1818

19-
@customElement('other-element')
20-
class _OtherElement extends GemElement {}
19+
@customElement('light-dom')
20+
class _OtherElement extends GemElement {
21+
render() {
22+
return html`<p>Other Content</p>`;
23+
}
24+
}
2125

2226
const style = createCSSSheet(css`
2327
:scope {
@@ -36,13 +40,11 @@ export class App extends GemElement {
3640
Text
3741
<header><h1>Header</h1></header>
3842
<p>Content</p>
39-
<other-element>
40-
<p>Other Content</p>
41-
</other-element>
43+
<light-dom></light-dom>
4244
<article>
4345
<p>Content</p>
4446
</article>
45-
<app-closed></app-closed>
47+
<closed-shadow-dom></closed-shadow-dom>
4648
`;
4749
}
4850
}

‎packages/gem/docs/en/001-guide/001-basic/001-reactive-element.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ class MyElement extends GemElement {
4141
> [!TIP]
4242
> Do not modify prop/attr within the element, they should be passed in one-way by the parent element, just like native elements
4343
44-
In addition, `GemElement` provides React-like `state`/`setState` API to manage the state of the element itself. an element re-rendered is triggered whenever `setState` is called:
44+
In addition, Gem provides the `createState` API to create the element's own state, and the created state object also acts as an update function, triggering the element to re-render when called.
4545

4646
```js
4747
// Omit import...
4848

4949
@customElement('my-element')
5050
class MyElement extends GemElement {
51-
state = { id: 1 };
52-
clicked() {
53-
this.setState({ id: 2 });
51+
#state = createState({ id: 1 });
52+
#clicked() {
53+
this.#state({ id: 2 });
5454
}
5555
render() {
56-
return html`${this.state.id}`;
56+
return html`${this.#state.id}`;
5757
}
5858
}
5959
```
@@ -152,3 +152,6 @@ Complete life cycle:
152152

153153
> [!NOTE]
154154
> The `constructor` and `unmounted` of the parent element are executed before the child element, but the `mounted` is executed after the child element
155+
156+
> [!WARNING]
157+
> The lifecycle may be replaced in the future by decorators based on `@effect` `@memo` `@willMount` `@renderTemplate` `@mounted` `@unmounted

‎packages/gem/docs/en/001-guide/001-basic/006-styled-element.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ You can reference CSS selectors in JS:
3131

3232
```js 17
3333
import { GemElement, html } from '@mantou/gem';
34-
import {
35-
createCSSSheet,
36-
styled,
37-
adoptedStyle,
38-
customElement,
39-
} from '@mantou/gem';
34+
import { createCSSSheet, styled, adoptedStyle, customElement } from '@mantou/gem';
4035

4136
const styles = createCSSSheet({
4237
header: styled.class`
@@ -56,6 +51,9 @@ class MyElement extends GemElement {
5651
}
5752
```
5853

54+
> [!NOTE]
55+
> Use `$` as a key to represent `:host, :scope` selectors, allowing styles to apply to both ShadowDOM and LightDOM.
56+
5957
## Customize the style outside the element
6058

6159
Use [`::part`](https://drafts.csswg.org/css-shadow-parts-1/#part)(only ShadowDOM) to export the internal content of the element, allowing external custom styles:
@@ -95,7 +93,7 @@ class MyElement extends GemElement {
9593
```
9694

9795
> [!NOTE]
98-
> Note the difference with `state`/`setState`
96+
> Note the difference with `createState`
9997
10098
> [!TIP]
10199
> Can also customize element styles using hack, for example:

‎packages/gem/docs/en/001-guide/002-advance/003-theme.md

+4
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ class App extends GemElement {
9595
}
9696
}
9797
```
98+
99+
## Scoped and override theme
100+
101+
<gbp-include src="../../snippets/scoped-theme.md"></gbp-include>

‎packages/gem/docs/en/001-guide/002-advance/010-debug.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ GemElement is a standard custom element that can be inspected and debugged in th
55
## Use Gem DevTools
66

77
![Gem DevTools](https://raw.githubusercontent.com/mantou132/gem/master/packages/gem-devtools/screenshot/firefox.jpg)
8+
9+
Features:
10+
11+
- Display all public non-standard members of the gem element, simple types allow editing
12+
- When the non Gem element is selected, statistical analysis of all custom elements on the page will be displayed.

0 commit comments

Comments
 (0)