create-mendix-widget-gleam 2.0.8 → 2.0.9
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/package.json +1 -1
- package/template/docs/glendix_guide.md +41 -43
- package/template/gleam.toml +1 -1
package/package.json
CHANGED
|
@@ -322,71 +322,69 @@ react.component_el(binding.resolve(rc, "PieChart"), attrs, children)
|
|
|
322
322
|
react.void_component_el(binding.resolve(rc, "Tooltip"), attrs)
|
|
323
323
|
```
|
|
324
324
|
|
|
325
|
-
|
|
325
|
+
## .mpk 위젯 컴포넌트 사용
|
|
326
326
|
|
|
327
|
-
`
|
|
327
|
+
`widgets/` 디렉토리에 `.mpk` 파일(Mendix 위젯 빌드 결과물)을 배치하면, 다른 위젯 안에서 기존 Mendix 위젯을 React 컴포넌트로 렌더링할 수 있다.
|
|
328
328
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
프로젝트 루트에 `widgets/` 디렉토리를 만들고 `.mpk` 파일을 복사합니다:
|
|
329
|
+
### 1단계: `.mpk` 파일 배치
|
|
332
330
|
|
|
333
331
|
```
|
|
334
|
-
|
|
332
|
+
프로젝트 루트/
|
|
335
333
|
├── widgets/
|
|
336
334
|
│ ├── Switch.mpk
|
|
337
335
|
│ └── Badge.mpk
|
|
338
336
|
├── src/
|
|
339
|
-
|
|
340
|
-
└── ...
|
|
337
|
+
└── gleam.toml
|
|
341
338
|
```
|
|
342
339
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
install 시 두 가지가 자동 수행됩니다:
|
|
346
|
-
- `.mpk` 내부의 `.mjs`와 `.css`가 추출되고, `widget_ffi.mjs`가 생성됩니다
|
|
347
|
-
- `.mpk` XML의 `<property>` 정의가 부모 위젯 XML(`src/{WidgetName}.xml`)에 `<propertyGroup caption="{위젯명}">` 으로 자동 주입됩니다 (동일 caption이 이미 있으면 건너뜀)
|
|
340
|
+
### 2단계: 바인딩 생성
|
|
348
341
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
```xml
|
|
352
|
-
<propertyGroup caption="Switch">
|
|
353
|
-
<property key="booleanAttribute" type="attribute">
|
|
354
|
-
<caption>Boolean attribute</caption>
|
|
355
|
-
<description>Attribute to toggle</description>
|
|
356
|
-
<attributeTypes>
|
|
357
|
-
<attributeType name="Boolean" />
|
|
358
|
-
</attributeTypes>
|
|
359
|
-
</property>
|
|
360
|
-
<property key="action" type="action" required="false">
|
|
361
|
-
<caption>On change</caption>
|
|
362
|
-
<description>Action to be performed when the switch is toggled</description>
|
|
363
|
-
</property>
|
|
364
|
-
</propertyGroup>
|
|
342
|
+
```bash
|
|
343
|
+
gleam run -m glendix/install
|
|
365
344
|
```
|
|
366
345
|
|
|
367
|
-
|
|
346
|
+
실행 시 다음이 자동 처리된다:
|
|
347
|
+
- `.mpk`에서 `.mjs`/`.css`를 추출하고 `widget_ffi.mjs`가 생성된다
|
|
348
|
+
- `.mpk` XML의 `<property>` 정의를 파싱하여 `src/widgets/`에 바인딩 `.gleam` 파일이 자동 생성된다 (이미 존재하면 건너뜀)
|
|
349
|
+
|
|
350
|
+
### 3단계: 자동 생성된 `src/widgets/*.gleam` 파일 확인
|
|
368
351
|
|
|
369
352
|
```gleam
|
|
353
|
+
// src/widgets/switch.gleam (자동 생성)
|
|
370
354
|
import glendix/mendix
|
|
371
|
-
import glendix/
|
|
372
|
-
import glendix/react
|
|
355
|
+
import glendix/react.{type JsProps, type ReactElement}
|
|
373
356
|
import glendix/react/attribute
|
|
357
|
+
import glendix/widget
|
|
374
358
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
let
|
|
359
|
+
/// Switch 위젯 렌더링 - props에서 속성을 읽어 위젯에 전달
|
|
360
|
+
pub fn render(props: JsProps) -> ReactElement {
|
|
361
|
+
let boolean_attribute = mendix.get_prop_required(props, "booleanAttribute")
|
|
362
|
+
let action = mendix.get_prop_required(props, "action")
|
|
378
363
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
364
|
+
let comp = widget.component("Switch")
|
|
365
|
+
react.component_el(
|
|
366
|
+
comp,
|
|
367
|
+
[
|
|
368
|
+
attribute.attribute("booleanAttribute", boolean_attribute),
|
|
369
|
+
attribute.attribute("action", action),
|
|
370
|
+
],
|
|
371
|
+
[],
|
|
372
|
+
)
|
|
373
|
+
}
|
|
385
374
|
```
|
|
386
375
|
|
|
387
|
-
|
|
376
|
+
required/optional 속성이 자동 구분되며, 필요에 따라 생성된 파일을 자유롭게 수정할 수 있다.
|
|
377
|
+
|
|
378
|
+
### 4단계: 위젯에서 사용
|
|
379
|
+
|
|
380
|
+
```gleam
|
|
381
|
+
import widgets/switch
|
|
382
|
+
|
|
383
|
+
// 컴포넌트 내부에서
|
|
384
|
+
switch.render(props)
|
|
385
|
+
```
|
|
388
386
|
|
|
389
|
-
|
|
387
|
+
위젯 이름은 `.mpk` 내부 XML의 `<name>` 값을, property key는 `.mpk` XML의 원본 key를 그대로 사용한다.
|
|
390
388
|
|
|
391
389
|
### 3.2 HTML 속성
|
|
392
390
|
|
package/template/gleam.toml
CHANGED