create-mendix-widget-gleam 2.0.0 → 2.0.2
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 +1 -1
- package/package.json +1 -1
- package/src/index.mjs +31 -13
- package/template/docs/glendix_guide.md +33 -32
- package/template/gleam.toml +1 -1
- package/template/widgets/README.md +82 -0
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.
|
|
33
|
+
gleam.toml # Gleam 프로젝트 설정 (glendix >= 2.0.2 의존성 포함)
|
|
34
34
|
CLAUDE.md # AI 어시스턴트용 프로젝트 컨텍스트
|
|
35
35
|
```
|
|
36
36
|
|
package/package.json
CHANGED
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>\`
|
|
466
|
+
- \`.mpk\` XML의 \`<property>\` 정의를 파싱하여 \`src/widgets/\`에 바인딩 \`.gleam\` 파일이 자동 생성된다 (이미 존재하면 건너뜀)
|
|
467
467
|
|
|
468
|
-
### 3단계:
|
|
468
|
+
### 3단계: 자동 생성된 \`src/widgets/*.gleam\` 파일 확인
|
|
469
469
|
|
|
470
470
|
\`\`\`gleam
|
|
471
|
+
// src/widgets/switch.gleam (자동 생성)
|
|
471
472
|
import glendix/mendix
|
|
472
|
-
import glendix/
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
let
|
|
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
|
-
|
|
481
|
-
|
|
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>\`
|
|
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>`
|
|
347
|
+
- `.mpk` XML의 `<property>` 정의를 파싱하여 `src/widgets/`에 바인딩 `.gleam` 파일이 자동 생성됩니다 (이미 존재하면 건너뜀)
|
|
348
348
|
|
|
349
|
-
예를 들어 `Switch.mpk`를 설치하면,
|
|
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/
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
let
|
|
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
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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>` 태그
|
|
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
|
|
package/template/gleam.toml
CHANGED
|
@@ -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`을 사용한다
|