create-mendix-widget-gleam 2.0.1 → 2.0.3

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/README.md CHANGED
@@ -30,7 +30,7 @@ my-widget/
30
30
  widgets/ # .mpk 위젯 파일 (glendix/widget로 바인딩)
31
31
  bindings.json # 외부 React 컴포넌트 바인딩 설정
32
32
  package.json # npm 의존성 (React, 외부 라이브러리 등)
33
- gleam.toml # Gleam 프로젝트 설정 (glendix >= 2.0.1 의존성 포함)
33
+ gleam.toml # Gleam 프로젝트 설정 (glendix >= 2.0.3 의존성 포함)
34
34
  CLAUDE.md # AI 어시스턴트용 프로젝트 컨텍스트
35
35
  ```
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mendix-widget-gleam",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Scaffold a Mendix Pluggable Widget powered by Gleam",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/src/index.mjs CHANGED
@@ -463,28 +463,46 @@ gleam run -m glendix/install
463
463
 
464
464
  실행 시 다음이 자동 처리된다:
465
465
  - \`.mpk\`에서 \`.mjs\`/\`.css\`를 추출하고 \`widget_ffi.mjs\`가 생성된다
466
- - \`.mpk\` XML의 \`<property>\` 정의가 부모 위젯 XML에 자동 주입된다
466
+ - \`.mpk\` XML의 \`<property>\` 정의를 파싱하여 \`src/widgets/\`에 바인딩 \`.gleam\` 파일이 자동 생성된다 (이미 존재하면 건너뜀)
467
467
 
468
- ### 3단계: Gleam에서 사용
468
+ ### 3단계: 자동 생성된 \`src/widgets/*.gleam\` 파일 확인
469
469
 
470
470
  \`\`\`gleam
471
+ // src/widgets/switch.gleam (자동 생성)
471
472
  import glendix/mendix
472
- import glendix/widget
473
- import glendix/react
473
+ import glendix/react.{type JsProps, type ReactElement}
474
474
  import glendix/react/attribute
475
+ import glendix/widget
475
476
 
476
- // props에서 자동 주입된 속성을 읽어 위젯에 전달
477
- let boolean_attr = mendix.get_prop_required(props, "booleanAttribute")
478
- let action = mendix.get_prop_required(props, "action")
477
+ /// Switch 위젯 렌더링 - props에서 속성을 읽어 위젯에 전달
478
+ pub fn render(props: JsProps) -> ReactElement {
479
+ let boolean_attribute = mendix.get_prop_required(props, "booleanAttribute")
480
+ let action = mendix.get_prop_required(props, "action")
481
+
482
+ let comp = widget.component("Switch")
483
+ react.component_el(
484
+ comp,
485
+ [
486
+ attribute.attribute("booleanAttribute", boolean_attribute),
487
+ attribute.attribute("action", action),
488
+ ],
489
+ [],
490
+ )
491
+ }
492
+ \`\`\`
493
+
494
+ required/optional 속성이 자동 구분되며, 필요에 따라 생성된 파일을 자유롭게 수정할 수 있다.
495
+
496
+ ### 4단계: 위젯에서 사용
497
+
498
+ \`\`\`gleam
499
+ import widgets/switch
479
500
 
480
- let switch_comp = widget.component("Switch")
481
- react.component_el(switch_comp, [
482
- attribute.attribute("booleanAttribute", boolean_attr),
483
- attribute.attribute("action", action),
484
- ], [])
501
+ // 컴포넌트 내부에서
502
+ switch.render(props)
485
503
  \`\`\`
486
504
 
487
- 위젯 이름은 \`.mpk\` 내부 XML의 \`<name>\` 값(PascalCase)을, property key는 \`.mpk\` XML의 원본 key를 그대로 사용한다.
505
+ 위젯 이름은 \`.mpk\` 내부 XML의 \`<name>\` 값을, property key는 \`.mpk\` XML의 원본 key를 그대로 사용한다.
488
506
 
489
507
  ## 기술 스택
490
508
 
@@ -344,47 +344,48 @@ my_widget/
344
344
 
345
345
  install 시 두 가지가 자동 수행됩니다:
346
346
  - `.mpk` 내부의 `.mjs`와 `.css`가 추출되고, `widget_ffi.mjs`가 생성됩니다
347
- - `.mpk` XML의 `<property>` 정의가 부모 위젯 XML(`src/{WidgetName}.xml`)에 `<propertyGroup caption="{위젯명}">` 으로 자동 주입됩니다 (동일 caption이 이미 있으면 건너뜀)
347
+ - `.mpk` XML의 `<property>` 정의를 파싱하여 `src/widgets/`에 바인딩 `.gleam` 파일이 자동 생성됩니다 (이미 존재하면 건너뜀)
348
348
 
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>
365
- ```
366
-
367
- **3단계: Gleam 코드에서 사용**
349
+ 예를 들어 `Switch.mpk`를 설치하면, `src/widgets/switch.gleam`이 자동 생성됩니다:
368
350
 
369
351
  ```gleam
352
+ // src/widgets/switch.gleam (자동 생성)
370
353
  import glendix/mendix
371
- import glendix/widget
372
- import glendix/react
354
+ import glendix/react.{type JsProps, type ReactElement}
373
355
  import glendix/react/attribute
356
+ import glendix/widget
374
357
 
375
- // props에서 자동 주입된 속성을 읽어 위젯에 전달
376
- let boolean_attr = mendix.get_prop_required(props, "booleanAttribute")
377
- let action = mendix.get_prop_required(props, "action")
358
+ /// Switch 위젯 렌더링 - props에서 속성을 읽어 위젯에 전달
359
+ pub fn render(props: JsProps) -> ReactElement {
360
+ let boolean_attribute = mendix.get_prop_required(props, "booleanAttribute")
361
+ let action = mendix.get_prop_required(props, "action")
378
362
 
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
- ], [])
363
+ let comp = widget.component("Switch")
364
+ react.component_el(
365
+ comp,
366
+ [
367
+ attribute.attribute("booleanAttribute", boolean_attribute),
368
+ attribute.attribute("action", action),
369
+ ],
370
+ [],
371
+ )
372
+ }
373
+ ```
374
+
375
+ optional 속성이 있으면 `optional_attr` 헬퍼와 `gleam/option` import가 자동 추가됩니다. Gleam 예약어(`type` 등)는 접미사 `_`로 회피합니다.
376
+
377
+ **3단계: 위젯에서 사용**
378
+
379
+ 생성된 `src/widgets/*.gleam` 파일을 import하여 사용합니다. 필요에 따라 자유롭게 수정할 수 있습니다.
380
+
381
+ ```gleam
382
+ import widgets/switch
383
+
384
+ // 컴포넌트 내부에서
385
+ switch.render(props)
385
386
  ```
386
387
 
387
- 위젯의 Props는 기존 `attribute.attribute(key, value)` 범용 함수로 전달합니다. 위젯 이름은 `.mpk` 내부 XML의 `<name>` 태그 값(PascalCase)을, property key는 `.mpk` XML의 원본 key를 그대로 사용합니다.
388
+ 위젯의 Props는 기존 `attribute.attribute(key, value)` 범용 함수로 전달합니다. 위젯 이름은 `.mpk` 내부 XML의 `<name>` 태그 값을, property key는 `.mpk` XML의 원본 key를 그대로 사용합니다.
388
389
 
389
390
  > `binding` 모듈과 달리 `widget` 모듈은 1 mpk = 1 컴포넌트이므로 `module` + `resolve` 2단계 없이 `component("Name")` 한 번에 가져옵니다.
390
391
 
@@ -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.1 and < 3.0.0"
11
+ glendix = ">= 2.0.3 and < 3.0.0"
@@ -0,0 +1,82 @@
1
+ # widgets/
2
+
3
+ Mendix 위젯 바인딩 디렉토리. `.mpk` 파일(Mendix 위젯 빌드 결과물)을 이 디렉토리에 배치하면, Gleam 코드에서 기존 Mendix 위젯을 React 컴포넌트로 렌더링할 수 있다.
4
+
5
+ ## 사용법
6
+
7
+ ### 1. `.mpk` 파일 배치
8
+
9
+ 빌드된 Mendix 위젯의 `.mpk` 파일을 이 디렉토리에 복사한다:
10
+
11
+ ```
12
+ widgets/
13
+ ├── Switch.mpk
14
+ ├── Badge.mpk
15
+ └── README.md
16
+ ```
17
+
18
+ ### 2. 바인딩 생성
19
+
20
+ ```bash
21
+ gleam run -m glendix/install
22
+ ```
23
+
24
+ 실행 시 다음이 자동 처리된다:
25
+
26
+ - `.mpk` 내부의 `.mjs`와 `.css`가 추출되고, `widget_ffi.mjs`가 생성된다
27
+ - `.mpk` XML의 `<property>` 정의를 파싱하여 `src/widgets/`에 바인딩 `.gleam` 파일이 자동 생성된다 (이미 존재하면 건너뜀)
28
+
29
+ ### 3. 자동 생성된 바인딩 확인
30
+
31
+ 예를 들어 `Switch.mpk`를 배치하면 `src/widgets/switch.gleam`이 생성된다:
32
+
33
+ ```gleam
34
+ // src/widgets/switch.gleam (자동 생성)
35
+ import glendix/mendix
36
+ import glendix/react.{type JsProps, type ReactElement}
37
+ import glendix/react/attribute
38
+ import glendix/widget
39
+
40
+ /// Switch 위젯 렌더링 - props에서 속성을 읽어 위젯에 전달
41
+ pub fn render(props: JsProps) -> ReactElement {
42
+ let boolean_attribute = mendix.get_prop_required(props, "booleanAttribute")
43
+ let action = mendix.get_prop_required(props, "action")
44
+
45
+ let comp = widget.component("Switch")
46
+ react.component_el(
47
+ comp,
48
+ [
49
+ attribute.attribute("booleanAttribute", boolean_attribute),
50
+ attribute.attribute("action", action),
51
+ ],
52
+ [],
53
+ )
54
+ }
55
+ ```
56
+
57
+ - required/optional 속성이 자동 구분된다
58
+ - optional 속성이 있으면 `optional_attr` 헬퍼와 `gleam/option` import가 자동 추가된다
59
+ - Gleam 예약어(`type` 등)는 접미사 `_`로 자동 회피된다
60
+ - 생성된 파일은 필요에 따라 자유롭게 수정 가능하다
61
+
62
+ ### 4. Gleam에서 사용
63
+
64
+ ```gleam
65
+ import widgets/switch
66
+
67
+ // 위젯 컴포넌트 내부에서
68
+ switch.render(props)
69
+ ```
70
+
71
+ ## 동작 원리
72
+
73
+ - `glendix/widget` 모듈의 `widget.component("Name")`으로 `.mpk` 위젯을 React 컴포넌트로 가져온다
74
+ - Props는 `attribute.attribute(key, value)` 범용 함수로 전달한다
75
+ - 위젯 이름은 `.mpk` 내부 XML의 `<name>` 값을, property key는 XML의 원본 key를 그대로 사용한다
76
+ - `binding` 모듈과 달리 1 mpk = 1 컴포넌트이므로 `widget.component("Name")` 한 번에 가져온다
77
+
78
+ ## 주의사항
79
+
80
+ - `.mpk` 파일을 추가/제거한 후에는 반드시 `gleam run -m glendix/install`을 다시 실행해야 한다
81
+ - `widget_ffi.mjs`는 자동 생성 파일이므로 직접 수정하지 않는다
82
+ - `.mpk` 위젯용 `.mjs` FFI 파일을 직접 작성하지 않는다 — `widgets/` 디렉토리 + `glendix/widget`을 사용한다