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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mendix-widget-gleam",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "Scaffold a Mendix Pluggable Widget powered by Gleam",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -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
- #### .mpk 위젯 컴포넌트 사용
325
+ ## .mpk 위젯 컴포넌트 사용
326
326
 
327
- `glendix/widget` 모듈로 `widgets/` 디렉토리의 `.mpk` 파일(Mendix 위젯 빌드 결과물)을 React 컴포넌트로 사용합니다. 다른 위젯 안에서 기존 Mendix 위젯을 렌더링할 유용합니다.
327
+ `widgets/` 디렉토리에 `.mpk` 파일(Mendix 위젯 빌드 결과물)을 배치하면, 다른 위젯 안에서 기존 Mendix 위젯을 React 컴포넌트로 렌더링할 있다.
328
328
 
329
- **1단계: `.mpk` 파일 배치**
330
-
331
- 프로젝트 루트에 `widgets/` 디렉토리를 만들고 `.mpk` 파일을 복사합니다:
329
+ ### 1단계: `.mpk` 파일 배치
332
330
 
333
331
  ```
334
- my_widget/
332
+ 프로젝트 루트/
335
333
  ├── widgets/
336
334
  │ ├── Switch.mpk
337
335
  │ └── Badge.mpk
338
336
  ├── src/
339
- ├── gleam.toml
340
- └── ...
337
+ └── gleam.toml
341
338
  ```
342
339
 
343
- **2단계: `gleam run -m glendix/install`** 실행 (위젯 바인딩 자동 생성)
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
- 예를 들어 `Switch.mpk`를 설치하면, 부모 위젯 XML에 다음이 자동 추가됩니다:
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
- **3단계: Gleam 코드에서 사용**
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/widget
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
- // props에서 자동 주입된 속성을 읽어 위젯에 전달
376
- let boolean_attr = mendix.get_prop_required(props, "booleanAttribute")
377
- let action = mendix.get_prop_required(props, "action")
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
- // widgets/Switch.mpk의 Switch 컴포넌트 사용
380
- let switch_comp = widget.component("Switch")
381
- react.component_el(switch_comp, [
382
- attribute.attribute("booleanAttribute", boolean_attr),
383
- attribute.attribute("action", action),
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
- 위젯의 Props는 기존 `attribute.attribute(key, value)` 범용 함수로 전달합니다. 위젯 이름은 `.mpk` 내부 XML의 `<name>` 태그 값(PascalCase)을, property key는 `.mpk` XML의 원본 key를 그대로 사용합니다.
376
+ required/optional 속성이 자동 구분되며, 필요에 따라 생성된 파일을 자유롭게 수정할 있다.
377
+
378
+ ### 4단계: 위젯에서 사용
379
+
380
+ ```gleam
381
+ import widgets/switch
382
+
383
+ // 컴포넌트 내부에서
384
+ switch.render(props)
385
+ ```
388
386
 
389
- > `binding` 모듈과 달리 `widget` 모듈은 1 mpk = 1 컴포넌트이므로 `module` + `resolve` 2단계 없이 `component("Name")` 한 번에 가져옵니다.
387
+ 위젯 이름은 `.mpk` 내부 XML의 `<name>` 값을, property key는 `.mpk` XML의 원본 key를 그대로 사용한다.
390
388
 
391
389
  ### 3.2 HTML 속성
392
390
 
@@ -8,4 +8,4 @@ runtime = "node"
8
8
 
9
9
  [dependencies]
10
10
  gleam_stdlib = ">= 0.44.0 and < 2.0.0"
11
- glendix = ">= 2.0.8 and < 3.0.0"
11
+ glendix = ">= 2.0.9 and < 3.0.0"