glendix

Gleam FFI bindings for React and Mendix Pluggable Widget API.

JSX 없이, 순수 Gleam으로 Mendix Pluggable Widget을 작성한다.

Installation

# gleam.toml
[dependencies]
glendix = { path = "../glendix" }

Hex 패키지 배포 전까지는 로컬 경로로 참조합니다.

Peer Dependencies

위젯 프로젝트의 package.json에 다음이 필요합니다:

{
  "dependencies": {
    "react": "^19.0.0",
    "big.js": "^6.0.0"
  }
}

Quick Start

import glendix/mendix
import glendix/react.{type JsProps, type ReactElement}
import glendix/react/html
import glendix/react/prop

pub fn widget(props: JsProps) -> ReactElement {
  let name = mendix.get_string_prop(props, "sampleText")
  html.div(prop.new() |> prop.class("my-widget"), [
    react.text("Hello " <> name),
  ])
}

fn(JsProps) -> ReactElement — 이것이 Mendix Pluggable Widget의 전부입니다.

Modules

React

ModuleDescription
glendix/react핵심 타입 (ReactElement, JsProps, Props) + el, fragment, text, none, when, when_some
glendix/react/propProps 파이프라인 빌더 — prop.new() |> prop.class("x") |> prop.on_click(handler)
glendix/react/hookReact Hooks — use_state, use_effect, use_memo, use_callback, use_ref
glendix/react/event이벤트 타입 + target_value, prevent_default, key
glendix/react/htmlHTML 태그 편의 함수 — div, span, input, button 등 (순수 Gleam, FFI 없음)

Mendix

ModuleDescription
glendix/mendix핵심 타입 (ValueStatus, ObjectItem) + JsProps 접근자 (get_prop, get_string_prop)
glendix/mendix/editable_value편집 가능한 값 — value, set_value, set_text_value, display_value
glendix/mendix/action액션 실행 — can_execute, execute, execute_if_can
glendix/mendix/dynamic_value동적 읽기 전용 값 (표현식 속성)
glendix/mendix/list_value리스트 데이터 — items, set_filter, set_sort_order, reload
glendix/mendix/list_attribute리스트 아이템별 접근 — ListAttributeValue, ListActionValue, ListWidgetValue
glendix/mendix/selection단일/다중 선택
glendix/mendix/reference연관 관계 (단일 참조, 다중 참조)
glendix/mendix/dateJS Date opaque 래퍼 (월: Gleam 1-based ↔ JS 0-based 자동 변환)
glendix/mendix/bigBig.js 고정밀 십진수 래퍼 (comparegleam/order.Order)
glendix/mendix/fileFileValue, WebImage
glendix/mendix/iconWebIcon — Glyph, Image, IconFont
glendix/mendix/formatterValueFormatterformat, parse
glendix/mendix/filterFilterCondition 빌더 — and_, or_, equals, contains, attribute, literal

Examples

Props 파이프라인

import glendix/react/prop

let props =
  prop.new()
  |> prop.class("btn btn-primary")
  |> prop.string("type", "submit")
  |> prop.bool("disabled", False)
  |> prop.on_click(fn(_event) { Nil })

useState + useEffect

import glendix/react
import glendix/react/hook
import glendix/react/html
import glendix/react/prop

pub fn counter(_props) -> react.ReactElement {
  let #(count, set_count) = hook.use_state(0)

  hook.use_effect_once(fn() {
    // 마운트 시 한 번 실행
    Nil
  })

  html.div_([
    html.button(
      prop.new() |> prop.on_click(fn(_) { set_count(count + 1) }),
      [react.text("Count: " <> int.to_string(count))],
    ),
  ])
}

Mendix EditableValue 읽기/쓰기

import gleam/option.{None, Some}
import glendix/mendix
import glendix/mendix/editable_value as ev

pub fn render_input(props: react.JsProps) -> react.ReactElement {
  case mendix.get_prop(props, "myAttribute") {
    Some(attr) -> {
      let display = ev.display_value(attr)
      let editable = ev.is_editable(attr)
      // ...
    }
    None -> react.none()
  }
}

조건부 렌더링

import glendix/react
import glendix/react/html

// Bool 기반
react.when(is_visible, fn() {
  html.div_([react.text("Visible!")])
})

// Option 기반
react.when_some(maybe_user, fn(user) {
  html.span_([react.text(user.name)])
})

Architecture

glendix/
  react.gleam           ← 핵심 타입 + createElement
  react_ffi.mjs         ← React 원시 함수 (얇은 어댑터)
  react/
    prop.gleam           ← Props 빌더
    hook.gleam           ← React Hooks
    event.gleam          ← 이벤트 타입
    html.gleam           ← HTML 태그 (순수 Gleam)
  mendix.gleam           ← Mendix 핵심 타입 + Props 접근자
  mendix_ffi.mjs         ← Mendix 런타임 타입 접근 (얇은 어댑터)
  mendix/
    editable_value.gleam ← EditableValue
    action.gleam         ← ActionValue
    dynamic_value.gleam  ← DynamicValue
    list_value.gleam     ← ListValue + Sort + Filter
    list_attribute.gleam ← List-linked 타입
    selection.gleam      ← Selection
    reference.gleam      ← Reference
    date.gleam           ← JS Date 래퍼
    big.gleam            ← Big.js 래퍼
    file.gleam           ← File / Image
    icon.gleam           ← Icon
    formatter.gleam      ← ValueFormatter
    filter.gleam         ← FilterCondition 빌더

Design Principles

License

Apache-2.0

Search Document