Skip to content

Commit 44ca2f3

Browse files
committed
docs: 플러그인 설정 스키마 조건부 표시 api 설명 및 예제 추가
1 parent 618ea1f commit 44ca2f3

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

docs/content/en/declarative-api/page.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,58 @@ settings: {
145145

146146
`type: "divider"` adds only a divider in the settings UI without needing `default` or `label`.
147147

148+
### Conditional Visibility (visible)
149+
150+
Add a `visible` property to setting items to dynamically show/hide them based on other setting values.
151+
Settings without `visible` are always shown (same as existing behavior).
152+
153+
```javascript
154+
settings: {
155+
// Mode selection
156+
showGraph: {
157+
type: "boolean",
158+
default: true,
159+
label: "Show Graph",
160+
},
161+
162+
// Static boolean — always hidden
163+
hiddenOption: {
164+
type: "number",
165+
default: 5,
166+
label: "Hidden Option",
167+
visible: false,
168+
},
169+
170+
// Function — dynamically show/hide based on other settings
171+
graphDivider: {
172+
type: "divider",
173+
visible: (settings) => settings.showGraph,
174+
},
175+
graphColor: {
176+
type: "color",
177+
default: "#86EFAC",
178+
label: "Graph Color",
179+
visible: (settings) => settings.showGraph,
180+
},
181+
graphSpeed: {
182+
type: "number",
183+
default: 1000,
184+
label: "Graph Speed (ms)",
185+
visible: (settings) => settings.showGraph,
186+
},
187+
},
188+
```
189+
190+
<Callout type="info">
191+
Hidden settings retain their stored values — only display is controlled, no data loss.
192+
</Callout>
193+
194+
The `visible` signature follows the same pattern as `PluginMenuItem.visible` in context menus:
195+
196+
```typescript
197+
visible?: boolean | ((settings: Record<string, any>) => boolean);
198+
```
199+
148200
### Accessing Settings
149201

150202
```javascript

docs/content/en/settings/page.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ const pluginSettings = dmn.plugin.defineSettings({
4949

5050
// `type: "divider"` adds only a divider in settings panel/modal.
5151

52+
// Conditional visibility — use visible property to dynamically show/hide items
53+
// Supports both static boolean and function
54+
advancedOption: {
55+
type: "number",
56+
default: 5,
57+
label: "Advanced Option",
58+
visible: (settings) => settings.enabled, // Only shown when enabled is true
59+
},
60+
5261
// Get settings values
5362
const current = pluginSettings.get();
5463
console.log("API Key:", current.apiKey);

docs/content/ko/declarative-api/page.mdx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,58 @@ settings: {
145145

146146
`type: "divider"`는 설정 UI에 구분선만 추가하며 `default``label`이 필요하지 않습니다.
147147

148+
### 조건부 표시 (visible)
149+
150+
설정 항목에 `visible` 속성을 추가하면 다른 설정값에 따라 동적으로 표시/숨김할 수 있습니다.
151+
`visible`이 없는 설정은 항상 표시됩니다 (기존 동작과 동일).
152+
153+
```javascript
154+
settings: {
155+
// 모드 선택
156+
showGraph: {
157+
type: "boolean",
158+
default: true,
159+
label: "그래프 표시",
160+
},
161+
162+
// 정적 boolean — 항상 숨김
163+
hiddenOption: {
164+
type: "number",
165+
default: 5,
166+
label: "숨겨진 옵션",
167+
visible: false,
168+
},
169+
170+
// 함수 — 다른 설정값에 따라 동적으로 표시/숨김
171+
graphDivider: {
172+
type: "divider",
173+
visible: (settings) => settings.showGraph,
174+
},
175+
graphColor: {
176+
type: "color",
177+
default: "#86EFAC",
178+
label: "그래프 색상",
179+
visible: (settings) => settings.showGraph,
180+
},
181+
graphSpeed: {
182+
type: "number",
183+
default: 1000,
184+
label: "그래프 속도 (ms)",
185+
visible: (settings) => settings.showGraph,
186+
},
187+
},
188+
```
189+
190+
<Callout type="info">
191+
숨겨진 설정의 저장값은 유지됩니다 — 표시만 제어하며 데이터 손실은 없습니다.
192+
</Callout>
193+
194+
`visible` 시그니처는 컨텍스트 메뉴의 `PluginMenuItem.visible`과 동일한 패턴입니다:
195+
196+
```typescript
197+
visible?: boolean | ((settings: Record<string, any>) => boolean);
198+
```
199+
148200
### 설정 접근
149201

150202
```javascript
@@ -522,7 +574,13 @@ dmn.plugin.defineElement({
522574
settings: {
523575
showGraph: { type: "boolean", default: true, label: "그래프 표시" },
524576
textColor: { type: "color", default: "#FFFFFF", label: "텍스트 색상" },
525-
graphColor: { type: "color", default: "#86EFAC", label: "그래프 색상" },
577+
graphDivider: { type: "divider", visible: (s) => s.showGraph },
578+
graphColor: {
579+
type: "color",
580+
default: "#86EFAC",
581+
label: "그래프 색상",
582+
visible: (s) => s.showGraph,
583+
},
526584
},
527585
528586
previewState: {

docs/content/ko/settings/page.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ const pluginSettings = dmn.plugin.defineSettings({
4949

5050
`type: "divider"`는 설정 패널/모달에 구분선만 추가합니다.
5151

52+
// 조건부 표시 — visible 속성으로 다른 설정값에 따라 동적으로 항목 표시/숨김
53+
// 정적 boolean 또는 함수 모두 지원
54+
advancedOption: {
55+
type: "number",
56+
default: 5,
57+
label: "고급 옵션",
58+
visible: (settings) => settings.enabled, // enabled가 true일 때만 표시
59+
},
60+
5261
// 설정값 조회
5362
const current = pluginSettings.get();
5463
console.log("API Key:", current.apiKey);
@@ -196,6 +205,13 @@ dmn.plugin.defineElement({
196205
// 인스턴스별 설정
197206
settings: {
198207
showGraph: { type: "boolean", default: true, label: "그래프 표시" },
208+
graphDivider: { type: "divider", visible: (s) => s.showGraph },
209+
graphColor: {
210+
type: "color",
211+
default: "#86EFAC",
212+
label: "그래프 색상",
213+
visible: (s) => s.showGraph,
214+
},
199215
},
200216

201217
template: (state, instanceSettings, { html }) => {

0 commit comments

Comments
 (0)