create-mendix-widget-gleam 3.0.2 → 4.0.1
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 +7 -9
- package/package.json +1 -1
- package/src/i18n.mjs +12 -15
- package/src/index.mjs +20 -33
- package/src/templates/claude_md.mjs +9 -8
- package/src/templates/readme_md.mjs +45 -318
- package/template/docs/glendix_guide.md +178 -131
- package/template/docs/mendraw_guide.md +328 -0
- package/template/gleam.toml +3 -1
- package/template/package.json +1 -6
- package/template/src/__widget_name__.gleam +1 -1
- package/template/src/editor_config.gleam +1 -1
- package/template/src/editor_preview.gleam +1 -1
- package/src/templates/widgets_readme.mjs +0 -275
- package/template/rollup.config.mjs +0 -10
- package/template/widgets/README.md +0 -1
|
@@ -33,11 +33,11 @@ A Mendix Pluggable Widget written in Gleam.
|
|
|
33
33
|
|
|
34
34
|
## Core Principles
|
|
35
35
|
|
|
36
|
-
The Gleam function \`fn(JsProps) -> Element\` has the same signature as a React functional component. React bindings come from the \`redraw\`/\`redraw_dom\` packages, while
|
|
36
|
+
The Gleam function \`fn(JsProps) -> Element\` has the same signature as a React functional component. React bindings come from the \`redraw\`/\`redraw_dom\` packages, while mendraw handles Mendix API access and JS interop, so widget projects only need to focus on business logic.
|
|
37
37
|
|
|
38
38
|
\`\`\`gleam
|
|
39
39
|
// src/${names.snakeCase}.gleam
|
|
40
|
-
import
|
|
40
|
+
import mendraw/mendix.{type JsProps}
|
|
41
41
|
import redraw.{type Element}
|
|
42
42
|
import redraw/dom/attribute
|
|
43
43
|
import redraw/dom/html
|
|
@@ -53,9 +53,9 @@ pub fn widget(props: JsProps) -> Element {
|
|
|
53
53
|
Mendix complex types can also be used type-safely from Gleam:
|
|
54
54
|
|
|
55
55
|
\`\`\`gleam
|
|
56
|
-
import
|
|
57
|
-
import
|
|
58
|
-
import
|
|
56
|
+
import mendraw/mendix.{type JsProps}
|
|
57
|
+
import mendraw/mendix/editable_value
|
|
58
|
+
import mendraw/mendix/action
|
|
59
59
|
import redraw.{type Element}
|
|
60
60
|
|
|
61
61
|
pub fn widget(props: JsProps) -> Element {
|
|
@@ -105,7 +105,7 @@ gleam run -m glendix/start # Link with Mendix test project
|
|
|
105
105
|
gleam run -m glendix/lint # Run ESLint
|
|
106
106
|
gleam run -m glendix/lint_fix # ESLint auto-fix
|
|
107
107
|
gleam run -m glendix/release # Release build
|
|
108
|
-
gleam run -m
|
|
108
|
+
gleam run -m mendraw/marketplace # Search/download Marketplace widgets
|
|
109
109
|
gleam run -m glendix/define # Widget property definition TUI editor
|
|
110
110
|
gleam build --target javascript # Gleam → JS compilation only
|
|
111
111
|
gleam test # Run tests
|
|
@@ -122,12 +122,10 @@ src/
|
|
|
122
122
|
components/
|
|
123
123
|
hello_world.gleam # Shared Hello World component
|
|
124
124
|
${names.pascalCase}.xml # Widget property definitions
|
|
125
|
-
widgets/ # .mpk widget files (bindings via glendix/widget)
|
|
126
|
-
bindings.json # External React component binding configuration
|
|
127
125
|
package.json # npm dependencies (React, external libraries, etc.)
|
|
128
126
|
\`\`\`
|
|
129
127
|
|
|
130
|
-
React bindings come from [redraw](https://hexdocs.pm/redraw/)/[redraw_dom](https://hexdocs.pm/redraw_dom/), while Mendix API and JS Interop bindings are provided by [
|
|
128
|
+
React bindings come from [redraw](https://hexdocs.pm/redraw/)/[redraw_dom](https://hexdocs.pm/redraw_dom/), while Mendix API and JS Interop bindings are provided by [mendraw](https://hexdocs.pm/mendraw/).
|
|
131
129
|
|
|
132
130
|
## Using External React Components
|
|
133
131
|
|
|
@@ -139,16 +137,13 @@ React component libraries distributed as npm packages can be used from pure Glea
|
|
|
139
137
|
${installCmd} recharts
|
|
140
138
|
\`\`\`
|
|
141
139
|
|
|
142
|
-
### Step 2:
|
|
140
|
+
### Step 2: Add bindings to \`gleam.toml\`
|
|
143
141
|
|
|
144
|
-
|
|
142
|
+
Add a \`[tools.glendix.bindings]\` section to your \`gleam.toml\`:
|
|
145
143
|
|
|
146
|
-
\`\`\`
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
"components": ["PieChart", "Pie", "Cell", "Tooltip", "ResponsiveContainer"]
|
|
150
|
-
}
|
|
151
|
-
}
|
|
144
|
+
\`\`\`toml
|
|
145
|
+
[tools.glendix.bindings.recharts]
|
|
146
|
+
components = ["PieChart", "Pie", "Cell", "Tooltip", "ResponsiveContainer"]
|
|
152
147
|
\`\`\`
|
|
153
148
|
|
|
154
149
|
### Step 3: Generate bindings
|
|
@@ -163,7 +158,7 @@ gleam run -m glendix/install
|
|
|
163
158
|
|
|
164
159
|
\`\`\`gleam
|
|
165
160
|
import glendix/binding
|
|
166
|
-
import
|
|
161
|
+
import mendraw/interop
|
|
167
162
|
import redraw.{type Element}
|
|
168
163
|
import redraw/dom/attribute.{type Attribute}
|
|
169
164
|
|
|
@@ -180,97 +175,11 @@ pub fn tooltip(attrs: List(Attribute)) -> Element {
|
|
|
180
175
|
|
|
181
176
|
External React components follow the same calling pattern as \`html.div\`.
|
|
182
177
|
|
|
183
|
-
## Mendix Marketplace Widget Download
|
|
184
|
-
|
|
185
|
-
Interactively search and download widgets (.mpk) from the Mendix Marketplace. After download, binding \`.gleam\` files are generated automatically and ready to use.
|
|
186
|
-
|
|
187
|
-
### Preparation
|
|
188
|
-
|
|
189
|
-
Set your Mendix Personal Access Token in a \`.env\` file:
|
|
190
|
-
|
|
191
|
-
\`\`\`
|
|
192
|
-
MENDIX_PAT=your_personal_access_token
|
|
193
|
-
\`\`\`
|
|
194
|
-
|
|
195
|
-
> Generate a PAT from [Mendix Developer Settings](https://user-settings.mendix.com/link/developersettings) — click **New Token** under **Personal Access Tokens**. Required scope: \`mx:marketplace-content:read\`
|
|
196
|
-
|
|
197
|
-
### Run
|
|
198
|
-
|
|
199
|
-
\`\`\`bash
|
|
200
|
-
gleam run -m glendix/marketplace
|
|
201
|
-
\`\`\`
|
|
202
|
-
|
|
203
|
-
Search and select widgets in the interactive TUI. The \`.mpk\` is downloaded to the \`widgets/\` directory, and binding \`.gleam\` files are auto-generated in \`src/widgets/\`.
|
|
204
|
-
|
|
205
|
-
## Using .mpk Widget Components
|
|
206
|
-
|
|
207
|
-
Place \`.mpk\` files (Mendix widget build artifacts) in the \`widgets/\` directory to render existing Mendix widgets as React components within your own widget.
|
|
208
|
-
|
|
209
|
-
### Step 1: Place the \`.mpk\` files
|
|
210
|
-
|
|
211
|
-
\`\`\`
|
|
212
|
-
project root/
|
|
213
|
-
├── widgets/
|
|
214
|
-
│ ├── Switch.mpk
|
|
215
|
-
│ └── Badge.mpk
|
|
216
|
-
├── src/
|
|
217
|
-
└── gleam.toml
|
|
218
|
-
\`\`\`
|
|
219
|
-
|
|
220
|
-
### Step 2: Generate bindings
|
|
221
|
-
|
|
222
|
-
\`\`\`bash
|
|
223
|
-
gleam run -m glendix/install
|
|
224
|
-
\`\`\`
|
|
225
|
-
|
|
226
|
-
This automatically:
|
|
227
|
-
- Extracts \`.mjs\`/\`.css\` from \`.mpk\` and generates \`widget_ffi.mjs\`
|
|
228
|
-
- Parses \`<property>\` definitions from \`.mpk\` XML and generates binding \`.gleam\` files in \`src/widgets/\` (existing files are skipped)
|
|
229
|
-
|
|
230
|
-
### Step 3: Review auto-generated \`src/widgets/*.gleam\` files
|
|
231
|
-
|
|
232
|
-
\`\`\`gleam
|
|
233
|
-
// src/widgets/switch.gleam (auto-generated)
|
|
234
|
-
import glendix/mendix.{type JsProps}
|
|
235
|
-
import glendix/interop
|
|
236
|
-
import redraw.{type Element}
|
|
237
|
-
import redraw/dom/attribute
|
|
238
|
-
import glendix/widget
|
|
239
|
-
|
|
240
|
-
/// Render Switch widget - reads properties from props and passes them to the widget
|
|
241
|
-
pub fn render(props: JsProps) -> Element {
|
|
242
|
-
let boolean_attribute = mendix.get_prop_required(props, "booleanAttribute")
|
|
243
|
-
let action = mendix.get_prop_required(props, "action")
|
|
244
|
-
|
|
245
|
-
let comp = widget.component("Switch")
|
|
246
|
-
interop.component_el(
|
|
247
|
-
comp,
|
|
248
|
-
[
|
|
249
|
-
attribute.attribute("booleanAttribute", boolean_attribute),
|
|
250
|
-
attribute.attribute("action", action),
|
|
251
|
-
],
|
|
252
|
-
[],
|
|
253
|
-
)
|
|
254
|
-
}
|
|
255
|
-
\`\`\`
|
|
256
|
-
|
|
257
|
-
Required/optional properties are distinguished automatically. You can freely modify the generated files as needed.
|
|
258
|
-
|
|
259
|
-
### Step 4: Use in your widget
|
|
260
|
-
|
|
261
|
-
\`\`\`gleam
|
|
262
|
-
import widgets/switch
|
|
263
|
-
|
|
264
|
-
// Inside a component
|
|
265
|
-
switch.render(props)
|
|
266
|
-
\`\`\`
|
|
267
|
-
|
|
268
|
-
Widget names use the \`<name>\` value from the \`.mpk\`'s internal XML, and property keys use the original keys from the \`.mpk\` XML.
|
|
269
|
-
|
|
270
178
|
## Tech Stack
|
|
271
179
|
|
|
272
180
|
- **Gleam** → JavaScript compilation
|
|
273
|
-
- **[glendix](https://hexdocs.pm/glendix/)** —
|
|
181
|
+
- **[glendix](https://hexdocs.pm/glendix/)** — Build tools + JS Interop Gleam bindings
|
|
182
|
+
- **[mendraw](https://hexdocs.pm/mendraw/)** — Mendix API Gleam bindings
|
|
274
183
|
- **[redraw](https://hexdocs.pm/redraw/)** / **[redraw_dom](https://hexdocs.pm/redraw_dom/)** — React Gleam bindings
|
|
275
184
|
- **Mendix Pluggable Widget** (React 19)
|
|
276
185
|
- **${pm}** — Package manager
|
|
@@ -292,11 +201,11 @@ Gleam 언어로 작성된 Mendix Pluggable Widget.
|
|
|
292
201
|
|
|
293
202
|
## 핵심 원리
|
|
294
203
|
|
|
295
|
-
Gleam 함수 \`fn(JsProps) -> Element\`는 React 함수형 컴포넌트와 동일한 시그니처다. React 바인딩은 \`redraw\`/\`redraw_dom\` 패키지가, Mendix API 접근과 JS interop은
|
|
204
|
+
Gleam 함수 \`fn(JsProps) -> Element\`는 React 함수형 컴포넌트와 동일한 시그니처다. React 바인딩은 \`redraw\`/\`redraw_dom\` 패키지가, Mendix API 접근과 JS interop은 mendraw가 제공하므로, 위젯 프로젝트에서는 비즈니스 로직에만 집중하면 된다.
|
|
296
205
|
|
|
297
206
|
\`\`\`gleam
|
|
298
207
|
// src/${names.snakeCase}.gleam
|
|
299
|
-
import
|
|
208
|
+
import mendraw/mendix.{type JsProps}
|
|
300
209
|
import redraw.{type Element}
|
|
301
210
|
import redraw/dom/attribute
|
|
302
211
|
import redraw/dom/html
|
|
@@ -312,9 +221,9 @@ pub fn widget(props: JsProps) -> Element {
|
|
|
312
221
|
Mendix 복합 타입도 Gleam에서 타입 안전하게 사용할 수 있다:
|
|
313
222
|
|
|
314
223
|
\`\`\`gleam
|
|
315
|
-
import
|
|
316
|
-
import
|
|
317
|
-
import
|
|
224
|
+
import mendraw/mendix.{type JsProps}
|
|
225
|
+
import mendraw/mendix/editable_value
|
|
226
|
+
import mendraw/mendix/action
|
|
318
227
|
import redraw.{type Element}
|
|
319
228
|
|
|
320
229
|
pub fn widget(props: JsProps) -> Element {
|
|
@@ -364,7 +273,7 @@ gleam run -m glendix/start # Mendix 테스트 프로젝트 연동
|
|
|
364
273
|
gleam run -m glendix/lint # ESLint 실행
|
|
365
274
|
gleam run -m glendix/lint_fix # ESLint 자동 수정
|
|
366
275
|
gleam run -m glendix/release # 릴리즈 빌드
|
|
367
|
-
gleam run -m
|
|
276
|
+
gleam run -m mendraw/marketplace # Marketplace 위젯 검색/다운로드
|
|
368
277
|
gleam run -m glendix/define # 위젯 프로퍼티 정의 TUI 에디터
|
|
369
278
|
gleam build --target javascript # Gleam → JS 컴파일만
|
|
370
279
|
gleam test # 테스트 실행
|
|
@@ -381,12 +290,10 @@ src/
|
|
|
381
290
|
components/
|
|
382
291
|
hello_world.gleam # Hello World 공유 컴포넌트
|
|
383
292
|
${names.pascalCase}.xml # 위젯 속성 정의
|
|
384
|
-
widgets/ # .mpk 위젯 파일 (glendix/widget로 바인딩)
|
|
385
|
-
bindings.json # 외부 React 컴포넌트 바인딩 설정
|
|
386
293
|
package.json # npm 의존성 (React, 외부 라이브러리 등)
|
|
387
294
|
\`\`\`
|
|
388
295
|
|
|
389
|
-
React 바인딩은 [redraw](https://hexdocs.pm/redraw/)/[redraw_dom](https://hexdocs.pm/redraw_dom/)이, Mendix API 및 JS Interop 바인딩은 [
|
|
296
|
+
React 바인딩은 [redraw](https://hexdocs.pm/redraw/)/[redraw_dom](https://hexdocs.pm/redraw_dom/)이, Mendix API 및 JS Interop 바인딩은 [mendraw](https://hexdocs.pm/mendraw/)가 제공합니다.
|
|
390
297
|
|
|
391
298
|
## 외부 React 컴포넌트 사용
|
|
392
299
|
|
|
@@ -398,16 +305,13 @@ npm 패키지로 제공되는 React 컴포넌트 라이브러리를 \`.mjs\` FFI
|
|
|
398
305
|
${installCmd} recharts
|
|
399
306
|
\`\`\`
|
|
400
307
|
|
|
401
|
-
### 2단계: \`
|
|
308
|
+
### 2단계: \`gleam.toml\`에 바인딩 추가
|
|
402
309
|
|
|
403
|
-
|
|
310
|
+
\`gleam.toml\`에 \`[tools.glendix.bindings]\` 섹션을 추가한다:
|
|
404
311
|
|
|
405
|
-
\`\`\`
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
"components": ["PieChart", "Pie", "Cell", "Tooltip", "ResponsiveContainer"]
|
|
409
|
-
}
|
|
410
|
-
}
|
|
312
|
+
\`\`\`toml
|
|
313
|
+
[tools.glendix.bindings.recharts]
|
|
314
|
+
components = ["PieChart", "Pie", "Cell", "Tooltip", "ResponsiveContainer"]
|
|
411
315
|
\`\`\`
|
|
412
316
|
|
|
413
317
|
### 3단계: 바인딩 생성
|
|
@@ -422,7 +326,7 @@ gleam run -m glendix/install
|
|
|
422
326
|
|
|
423
327
|
\`\`\`gleam
|
|
424
328
|
import glendix/binding
|
|
425
|
-
import
|
|
329
|
+
import mendraw/interop
|
|
426
330
|
import redraw.{type Element}
|
|
427
331
|
import redraw/dom/attribute.{type Attribute}
|
|
428
332
|
|
|
@@ -439,97 +343,11 @@ pub fn tooltip(attrs: List(Attribute)) -> Element {
|
|
|
439
343
|
|
|
440
344
|
\`html.div\`와 동일한 호출 패턴으로 외부 React 컴포넌트를 사용할 수 있다.
|
|
441
345
|
|
|
442
|
-
## Mendix Marketplace 위젯 다운로드
|
|
443
|
-
|
|
444
|
-
Mendix Marketplace에서 위젯(.mpk)을 인터랙티브하게 검색하고 다운로드할 수 있다. 다운로드 완료 후 바인딩 \`.gleam\` 파일이 자동 생성되어 바로 사용 가능하다.
|
|
445
|
-
|
|
446
|
-
### 사전 준비
|
|
447
|
-
|
|
448
|
-
\`.env\` 파일에 Mendix Personal Access Token을 설정한다:
|
|
449
|
-
|
|
450
|
-
\`\`\`
|
|
451
|
-
MENDIX_PAT=your_personal_access_token
|
|
452
|
-
\`\`\`
|
|
453
|
-
|
|
454
|
-
> PAT는 [Mendix Developer Settings](https://user-settings.mendix.com/link/developersettings)에서 **Personal Access Tokens** 섹션의 **New Token**을 클릭하여 발급. 필요한 scope: \`mx:marketplace-content:read\`
|
|
455
|
-
|
|
456
|
-
### 실행
|
|
457
|
-
|
|
458
|
-
\`\`\`bash
|
|
459
|
-
gleam run -m glendix/marketplace
|
|
460
|
-
\`\`\`
|
|
461
|
-
|
|
462
|
-
인터랙티브 TUI에서 위젯을 검색/선택하면 \`widgets/\` 디렉토리에 \`.mpk\`가 다운로드되고, \`src/widgets/\`에 바인딩 \`.gleam\` 파일이 자동 생성된다.
|
|
463
|
-
|
|
464
|
-
## .mpk 위젯 컴포넌트 사용
|
|
465
|
-
|
|
466
|
-
\`widgets/\` 디렉토리에 \`.mpk\` 파일(Mendix 위젯 빌드 결과물)을 배치하면, 다른 위젯 안에서 기존 Mendix 위젯을 React 컴포넌트로 렌더링할 수 있다.
|
|
467
|
-
|
|
468
|
-
### 1단계: \`.mpk\` 파일 배치
|
|
469
|
-
|
|
470
|
-
\`\`\`
|
|
471
|
-
프로젝트 루트/
|
|
472
|
-
├── widgets/
|
|
473
|
-
│ ├── Switch.mpk
|
|
474
|
-
│ └── Badge.mpk
|
|
475
|
-
├── src/
|
|
476
|
-
└── gleam.toml
|
|
477
|
-
\`\`\`
|
|
478
|
-
|
|
479
|
-
### 2단계: 바인딩 생성
|
|
480
|
-
|
|
481
|
-
\`\`\`bash
|
|
482
|
-
gleam run -m glendix/install
|
|
483
|
-
\`\`\`
|
|
484
|
-
|
|
485
|
-
실행 시 다음이 자동 처리된다:
|
|
486
|
-
- \`.mpk\`에서 \`.mjs\`/\`.css\`를 추출하고 \`widget_ffi.mjs\`가 생성된다
|
|
487
|
-
- \`.mpk\` XML의 \`<property>\` 정의를 파싱하여 \`src/widgets/\`에 바인딩 \`.gleam\` 파일이 자동 생성된다 (이미 존재하면 건너뜀)
|
|
488
|
-
|
|
489
|
-
### 3단계: 자동 생성된 \`src/widgets/*.gleam\` 파일 확인
|
|
490
|
-
|
|
491
|
-
\`\`\`gleam
|
|
492
|
-
// src/widgets/switch.gleam (자동 생성)
|
|
493
|
-
import glendix/mendix.{type JsProps}
|
|
494
|
-
import glendix/interop
|
|
495
|
-
import redraw.{type Element}
|
|
496
|
-
import redraw/dom/attribute
|
|
497
|
-
import glendix/widget
|
|
498
|
-
|
|
499
|
-
/// Switch 위젯 렌더링 - props에서 속성을 읽어 위젯에 전달
|
|
500
|
-
pub fn render(props: JsProps) -> Element {
|
|
501
|
-
let boolean_attribute = mendix.get_prop_required(props, "booleanAttribute")
|
|
502
|
-
let action = mendix.get_prop_required(props, "action")
|
|
503
|
-
|
|
504
|
-
let comp = widget.component("Switch")
|
|
505
|
-
interop.component_el(
|
|
506
|
-
comp,
|
|
507
|
-
[
|
|
508
|
-
attribute.attribute("booleanAttribute", boolean_attribute),
|
|
509
|
-
attribute.attribute("action", action),
|
|
510
|
-
],
|
|
511
|
-
[],
|
|
512
|
-
)
|
|
513
|
-
}
|
|
514
|
-
\`\`\`
|
|
515
|
-
|
|
516
|
-
required/optional 속성이 자동 구분되며, 필요에 따라 생성된 파일을 자유롭게 수정할 수 있다.
|
|
517
|
-
|
|
518
|
-
### 4단계: 위젯에서 사용
|
|
519
|
-
|
|
520
|
-
\`\`\`gleam
|
|
521
|
-
import widgets/switch
|
|
522
|
-
|
|
523
|
-
// 컴포넌트 내부에서
|
|
524
|
-
switch.render(props)
|
|
525
|
-
\`\`\`
|
|
526
|
-
|
|
527
|
-
위젯 이름은 \`.mpk\` 내부 XML의 \`<name>\` 값을, property key는 \`.mpk\` XML의 원본 key를 그대로 사용한다.
|
|
528
|
-
|
|
529
346
|
## 기술 스택
|
|
530
347
|
|
|
531
348
|
- **Gleam** → JavaScript 컴파일
|
|
532
|
-
- **[glendix](https://hexdocs.pm/glendix/)** —
|
|
349
|
+
- **[glendix](https://hexdocs.pm/glendix/)** — 빌드 도구 + JS Interop Gleam 바인딩
|
|
350
|
+
- **[mendraw](https://hexdocs.pm/mendraw/)** — Mendix API Gleam 바인딩
|
|
533
351
|
- **[redraw](https://hexdocs.pm/redraw/)** / **[redraw_dom](https://hexdocs.pm/redraw_dom/)** — React Gleam 바인딩
|
|
534
352
|
- **Mendix Pluggable Widget** (React 19)
|
|
535
353
|
- **${pm}** — 패키지 매니저
|
|
@@ -551,11 +369,11 @@ Gleam言語で作成されたMendix Pluggable Widget。
|
|
|
551
369
|
|
|
552
370
|
## 基本原理
|
|
553
371
|
|
|
554
|
-
Gleam関数 \`fn(JsProps) -> Element\` はReact関数コンポーネントと同一のシグネチャを持つ。Reactバインディングは\`redraw\`/\`redraw_dom\`パッケージが、Mendix APIアクセスとJS interopは
|
|
372
|
+
Gleam関数 \`fn(JsProps) -> Element\` はReact関数コンポーネントと同一のシグネチャを持つ。Reactバインディングは\`redraw\`/\`redraw_dom\`パッケージが、Mendix APIアクセスとJS interopはmendrawが提供するため、ウィジェットプロジェクトではビジネスロジックにのみ集中すればよい。
|
|
555
373
|
|
|
556
374
|
\`\`\`gleam
|
|
557
375
|
// src/${names.snakeCase}.gleam
|
|
558
|
-
import
|
|
376
|
+
import mendraw/mendix.{type JsProps}
|
|
559
377
|
import redraw.{type Element}
|
|
560
378
|
import redraw/dom/attribute
|
|
561
379
|
import redraw/dom/html
|
|
@@ -571,9 +389,9 @@ pub fn widget(props: JsProps) -> Element {
|
|
|
571
389
|
Mendixの複合型もGleamから型安全に使用できる:
|
|
572
390
|
|
|
573
391
|
\`\`\`gleam
|
|
574
|
-
import
|
|
575
|
-
import
|
|
576
|
-
import
|
|
392
|
+
import mendraw/mendix.{type JsProps}
|
|
393
|
+
import mendraw/mendix/editable_value
|
|
394
|
+
import mendraw/mendix/action
|
|
577
395
|
import redraw.{type Element}
|
|
578
396
|
|
|
579
397
|
pub fn widget(props: JsProps) -> Element {
|
|
@@ -623,7 +441,7 @@ gleam run -m glendix/start # Mendixテストプロジェクト連携
|
|
|
623
441
|
gleam run -m glendix/lint # ESLint実行
|
|
624
442
|
gleam run -m glendix/lint_fix # ESLint自動修正
|
|
625
443
|
gleam run -m glendix/release # リリースビルド
|
|
626
|
-
gleam run -m
|
|
444
|
+
gleam run -m mendraw/marketplace # Marketplaceウィジェット検索/ダウンロード
|
|
627
445
|
gleam run -m glendix/define # ウィジェットプロパティ定義TUIエディター
|
|
628
446
|
gleam build --target javascript # Gleam → JSコンパイルのみ
|
|
629
447
|
gleam test # テスト実行
|
|
@@ -640,12 +458,10 @@ src/
|
|
|
640
458
|
components/
|
|
641
459
|
hello_world.gleam # Hello World共有コンポーネント
|
|
642
460
|
${names.pascalCase}.xml # ウィジェットプロパティ定義
|
|
643
|
-
widgets/ # .mpkウィジェットファイル(glendix/widgetでバインディング)
|
|
644
|
-
bindings.json # 外部Reactコンポーネントバインディング設定
|
|
645
461
|
package.json # npm依存関係(React、外部ライブラリなど)
|
|
646
462
|
\`\`\`
|
|
647
463
|
|
|
648
|
-
Reactバインディングは[redraw](https://hexdocs.pm/redraw/)/[redraw_dom](https://hexdocs.pm/redraw_dom/)が、Mendix APIおよびJS Interopバインディングは[
|
|
464
|
+
Reactバインディングは[redraw](https://hexdocs.pm/redraw/)/[redraw_dom](https://hexdocs.pm/redraw_dom/)が、Mendix APIおよびJS Interopバインディングは[mendraw](https://hexdocs.pm/mendraw/)が提供する。
|
|
649
465
|
|
|
650
466
|
## 外部Reactコンポーネントの使用
|
|
651
467
|
|
|
@@ -657,16 +473,13 @@ npmパッケージとして提供されるReactコンポーネントライブラ
|
|
|
657
473
|
${installCmd} recharts
|
|
658
474
|
\`\`\`
|
|
659
475
|
|
|
660
|
-
### ステップ2:\`
|
|
476
|
+
### ステップ2:\`gleam.toml\`にバインディングを追加
|
|
661
477
|
|
|
662
|
-
|
|
478
|
+
\`gleam.toml\`に\`[tools.glendix.bindings]\`セクションを追加する:
|
|
663
479
|
|
|
664
|
-
\`\`\`
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
"components": ["PieChart", "Pie", "Cell", "Tooltip", "ResponsiveContainer"]
|
|
668
|
-
}
|
|
669
|
-
}
|
|
480
|
+
\`\`\`toml
|
|
481
|
+
[tools.glendix.bindings.recharts]
|
|
482
|
+
components = ["PieChart", "Pie", "Cell", "Tooltip", "ResponsiveContainer"]
|
|
670
483
|
\`\`\`
|
|
671
484
|
|
|
672
485
|
### ステップ3:バインディングの生成
|
|
@@ -681,7 +494,7 @@ gleam run -m glendix/install
|
|
|
681
494
|
|
|
682
495
|
\`\`\`gleam
|
|
683
496
|
import glendix/binding
|
|
684
|
-
import
|
|
497
|
+
import mendraw/interop
|
|
685
498
|
import redraw.{type Element}
|
|
686
499
|
import redraw/dom/attribute.{type Attribute}
|
|
687
500
|
|
|
@@ -698,97 +511,11 @@ pub fn tooltip(attrs: List(Attribute)) -> Element {
|
|
|
698
511
|
|
|
699
512
|
\`html.div\`と同じ呼び出しパターンで外部Reactコンポーネントを使用できる。
|
|
700
513
|
|
|
701
|
-
## Mendix Marketplaceウィジェットのダウンロード
|
|
702
|
-
|
|
703
|
-
Mendix Marketplaceからウィジェット(.mpk)をインタラクティブに検索・ダウンロードできる。ダウンロード完了後、バインディング\`.gleam\`ファイルが自動生成され、すぐに使用可能になる。
|
|
704
|
-
|
|
705
|
-
### 事前準備
|
|
706
|
-
|
|
707
|
-
\`.env\`ファイルにMendix Personal Access Tokenを設定する:
|
|
708
|
-
|
|
709
|
-
\`\`\`
|
|
710
|
-
MENDIX_PAT=your_personal_access_token
|
|
711
|
-
\`\`\`
|
|
712
|
-
|
|
713
|
-
> PATは[Mendix Developer Settings](https://user-settings.mendix.com/link/developersettings)の**Personal Access Tokens**セクションで**New Token**をクリックして発行。必要なscope:\`mx:marketplace-content:read\`
|
|
714
|
-
|
|
715
|
-
### 実行
|
|
716
|
-
|
|
717
|
-
\`\`\`bash
|
|
718
|
-
gleam run -m glendix/marketplace
|
|
719
|
-
\`\`\`
|
|
720
|
-
|
|
721
|
-
インタラクティブTUIでウィジェットを検索・選択すると、\`widgets/\`ディレクトリに\`.mpk\`がダウンロードされ、\`src/widgets/\`にバインディング\`.gleam\`ファイルが自動生成される。
|
|
722
|
-
|
|
723
|
-
## .mpkウィジェットコンポーネントの使用
|
|
724
|
-
|
|
725
|
-
\`widgets/\`ディレクトリに\`.mpk\`ファイル(Mendixウィジェットビルド成果物)を配置すると、別のウィジェット内から既存のMendixウィジェットをReactコンポーネントとしてレンダリングできる。
|
|
726
|
-
|
|
727
|
-
### ステップ1:\`.mpk\`ファイルの配置
|
|
728
|
-
|
|
729
|
-
\`\`\`
|
|
730
|
-
プロジェクトルート/
|
|
731
|
-
├── widgets/
|
|
732
|
-
│ ├── Switch.mpk
|
|
733
|
-
│ └── Badge.mpk
|
|
734
|
-
├── src/
|
|
735
|
-
└── gleam.toml
|
|
736
|
-
\`\`\`
|
|
737
|
-
|
|
738
|
-
### ステップ2:バインディングの生成
|
|
739
|
-
|
|
740
|
-
\`\`\`bash
|
|
741
|
-
gleam run -m glendix/install
|
|
742
|
-
\`\`\`
|
|
743
|
-
|
|
744
|
-
実行時に以下が自動処理される:
|
|
745
|
-
- \`.mpk\`から\`.mjs\`/\`.css\`を抽出し、\`widget_ffi.mjs\`が生成される
|
|
746
|
-
- \`.mpk\` XMLの\`<property>\`定義をパースし、\`src/widgets/\`にバインディング\`.gleam\`ファイルが自動生成される(既存ファイルはスキップ)
|
|
747
|
-
|
|
748
|
-
### ステップ3:自動生成された\`src/widgets/*.gleam\`ファイルの確認
|
|
749
|
-
|
|
750
|
-
\`\`\`gleam
|
|
751
|
-
// src/widgets/switch.gleam(自動生成)
|
|
752
|
-
import glendix/mendix.{type JsProps}
|
|
753
|
-
import glendix/interop
|
|
754
|
-
import redraw.{type Element}
|
|
755
|
-
import redraw/dom/attribute
|
|
756
|
-
import glendix/widget
|
|
757
|
-
|
|
758
|
-
/// Switchウィジェットのレンダリング - propsからプロパティを読み取りウィジェットに渡す
|
|
759
|
-
pub fn render(props: JsProps) -> Element {
|
|
760
|
-
let boolean_attribute = mendix.get_prop_required(props, "booleanAttribute")
|
|
761
|
-
let action = mendix.get_prop_required(props, "action")
|
|
762
|
-
|
|
763
|
-
let comp = widget.component("Switch")
|
|
764
|
-
interop.component_el(
|
|
765
|
-
comp,
|
|
766
|
-
[
|
|
767
|
-
attribute.attribute("booleanAttribute", boolean_attribute),
|
|
768
|
-
attribute.attribute("action", action),
|
|
769
|
-
],
|
|
770
|
-
[],
|
|
771
|
-
)
|
|
772
|
-
}
|
|
773
|
-
\`\`\`
|
|
774
|
-
|
|
775
|
-
required/optionalプロパティは自動的に区別され、生成されたファイルは自由に編集できる。
|
|
776
|
-
|
|
777
|
-
### ステップ4:ウィジェットで使用
|
|
778
|
-
|
|
779
|
-
\`\`\`gleam
|
|
780
|
-
import widgets/switch
|
|
781
|
-
|
|
782
|
-
// コンポーネント内で
|
|
783
|
-
switch.render(props)
|
|
784
|
-
\`\`\`
|
|
785
|
-
|
|
786
|
-
ウィジェット名は\`.mpk\`内部XMLの\`<name>\`値を、プロパティキーは\`.mpk\` XMLの元のキーをそのまま使用する。
|
|
787
|
-
|
|
788
514
|
## 技術スタック
|
|
789
515
|
|
|
790
516
|
- **Gleam** → JavaScriptコンパイル
|
|
791
|
-
- **[glendix](https://hexdocs.pm/glendix/)** —
|
|
517
|
+
- **[glendix](https://hexdocs.pm/glendix/)** — ビルドツール + JS Interop Gleamバインディング
|
|
518
|
+
- **[mendraw](https://hexdocs.pm/mendraw/)** — Mendix API Gleamバインディング
|
|
792
519
|
- **[redraw](https://hexdocs.pm/redraw/)** / **[redraw_dom](https://hexdocs.pm/redraw_dom/)** — React Gleamバインディング
|
|
793
520
|
- **Mendix Pluggable Widget**(React 19)
|
|
794
521
|
- **${pm}** — パッケージマネージャー
|