create-mendix-widget-gleam 2.0.8 → 2.0.11

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.11",
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
 
@@ -1710,6 +1708,8 @@ case formatter.parse(fmt, "123.45") {
1710
1708
 
1711
1709
  Studio Pro의 editorConfig에서 속성을 조건부로 숨기거나, 그룹을 탭으로 변환하는 등의 작업을 순수 Gleam으로 작성할 수 있습니다. `@mendix/pluggable-widgets-tools`의 헬퍼 함수를 래핑합니다.
1712
1710
 
1711
+ > **Jint 호환성**: Studio Pro는 editorConfig를 **Jint**(.NET JavaScript 엔진)로 실행합니다. Jint는 Gleam 컴파일러가 생성하는 `List` 런타임(WeakMap, Symbol.iterator, class inheritance)을 지원하지 않으므로, 이 모듈의 모든 함수는 `List` 타입을 사용하지 않습니다. 여러 키를 전달할 때는 **콤마 구분 String**을 사용합니다.
1712
+
1713
1713
  #### Properties 타입
1714
1714
 
1715
1715
  `Properties`는 Studio Pro가 `getProperties`에 전달하는 `PropertyGroup[]` 배열의 opaque 래퍼입니다. 모든 함수가 `Properties`를 반환하므로 파이프라인 체이닝이 가능합니다.
@@ -1722,14 +1722,14 @@ import glendix/editor_config.{type Properties}
1722
1722
  // 단일 속성 숨기기
1723
1723
  let props = editor_config.hide_property(default_properties, "barWidth")
1724
1724
 
1725
- // 여러 속성 한 번에 숨기기
1726
- let props = editor_config.hide_properties(default_properties, ["barWidth", "barColor"])
1725
+ // 여러 속성 한 번에 숨기기 (콤마 구분 String)
1726
+ let props = editor_config.hide_properties(default_properties, "barWidth,barColor")
1727
1727
 
1728
1728
  // 중첩 속성 숨기기 (배열 타입 속성의 특정 인덱스 내부)
1729
1729
  let props = editor_config.hide_nested_property(default_properties, "columns", 0, "width")
1730
1730
 
1731
- // 여러 중첩 속성 한 번에 숨기기
1732
- let props = editor_config.hide_nested_properties(default_properties, "columns", 0, ["width", "alignment"])
1731
+ // 여러 중첩 속성 한 번에 숨기기 (콤마 구분 String)
1732
+ let props = editor_config.hide_nested_properties(default_properties, "columns", 0, "width,alignment")
1733
1733
  ```
1734
1734
 
1735
1735
  #### 탭 변환 / 속성 순서 변경
@@ -1746,11 +1746,17 @@ let props = editor_config.move_property(default_properties, 0, 2)
1746
1746
 
1747
1747
  사용자의 `src/editor_config.gleam`에서 `getProperties` 로직을 작성합니다. 이 파일이 존재하면 `run_with_bridge` 실행 시 editorConfig 브릿지 JS가 자동 생성됩니다.
1748
1748
 
1749
+ > **주의**: editorConfig 코드에서는 Gleam `List`를 사용하지 마세요. `["a", "b"]` 같은 리스트 리터럴은 Gleam List 런타임 클래스를 번들에 포함시켜 Jint에서 크래시를 일으킵니다. 여러 키를 조합할 때는 `const`와 String 연결(`<>`)을 사용하세요.
1750
+
1749
1751
  ```gleam
1750
1752
  import glendix/editor_config.{type Properties}
1751
1753
  import glendix/mendix
1752
1754
  import glendix/react.{type JsProps}
1753
1755
 
1756
+ const bar_keys = "barWidth,barColor"
1757
+
1758
+ const line_keys = "lineStyle,lineCurve"
1759
+
1754
1760
  pub fn get_properties(
1755
1761
  values: JsProps,
1756
1762
  default_properties: Properties,
@@ -1761,10 +1767,10 @@ pub fn get_properties(
1761
1767
  let props = case chart_type {
1762
1768
  "line" ->
1763
1769
  default_properties
1764
- |> editor_config.hide_properties(["barWidth", "barColor"])
1770
+ |> editor_config.hide_properties(bar_keys)
1765
1771
  "bar" ->
1766
1772
  default_properties
1767
- |> editor_config.hide_properties(["lineStyle", "lineCurve"])
1773
+ |> editor_config.hide_properties(line_keys)
1768
1774
  _ -> default_properties
1769
1775
  }
1770
1776
 
@@ -1780,9 +1786,9 @@ pub fn get_properties(
1780
1786
  | 함수 | 설명 |
1781
1787
  |------|------|
1782
1788
  | `hide_property(properties, key)` | 단일 속성 숨기기 |
1783
- | `hide_properties(properties, keys)` | 여러 속성 번에 숨기기 |
1789
+ | `hide_properties(properties, keys)` | 여러 속성 숨기기 (콤마 구분 String) |
1784
1790
  | `hide_nested_property(properties, key, index, nested_key)` | 중첩 속성 숨기기 |
1785
- | `hide_nested_properties(properties, key, index, nested_keys)` | 여러 중첩 속성 숨기기 |
1791
+ | `hide_nested_properties(properties, key, index, nested_keys)` | 여러 중첩 속성 숨기기 (콤마 구분 String) |
1786
1792
  | `transform_groups_into_tabs(properties)` | 그룹 → 탭 변환 |
1787
1793
  | `move_property(properties, from_index, to_index)` | 속성 순서 변경 |
1788
1794
 
@@ -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.11 and < 3.0.0"