ProtoViewLogic: createElement()
与えられた記述子に基づいて Element
を生成します。
構文
ProtoViewLogic.createElement(componentDescriptor) => Element
引数
-
componentDescriptor
:object
定義する
Element
の記述子です。これは以下のプロパティを持つオブジェクトです:
-
tagName
:string
定義する
Element
のタグ名を指定します -
value
:string
|undefined
(省略可)定義する
Element
のvalue
属性の値を指定しますinfovalue
の指定はattributes
内のvalue
属性の指定に優先します(後者の値は前者の値で上書きされます)
-
text
:string
|undefined
(省略可)定義する
Element
のtextContent
を指定しますinfochildren
プロパティと併用した際、text
は定義されるElement
の最初のノード (firstNode
) として登録されます(結果としてchildren
のインデックスは 1 つずれることに注意してください)
-
children
:Array<Element | string | object>
|undefined
(省略可)定義する
Element
の子のノードとなる要素、テキスト、または要素の記述子を指定しますinfotext
プロパティと併用した際、定義されるElement
の最初のノード (firstNode
) としてtext
が先に登録され、それに続いてchildren
の成分が追加されます(結果としてchildren
のインデックスは 1 つずれることに注意してください)
-
primary
:string
|undefined
(省略可)定義する
Element
のdata-primary
カスタムデータ属性の値を指定しますinfoprimary
の指定はattributes
内のdata-primary
属性の指定に優先します(後者の値は前者の値で上書きされます)
-
activeEvents
:string
|Array<string>
|undefined
(省略可)定義する
Element
のdata-active-events
カスタムデータ属性を指定しますinfoactiveEvents
の指定はattributes
内のdata-active-events
属性の指定に優先します(後者の値は前者の値で上書きされます)string
として指定した場合、カンマ区切りされたイベント種別の文字列になっていなければなりません
-
attributes
:object
|undefined
(省略可)定義する
Element
の属性を指定します。定義する属性と同じ名前を持つプロパティに、設定する値を持たせたオブジェクトを指定します。
infovalue
,primary
,activeEvents
プロパティの指定はattributes
内のvalue
,data-primary
,data-active-events
属性の指定に優先します(後者の値は前者の値で上書きされます)attributes
内のid
属性の指定は常に無視され、記述子を持つプロパティ名 またはそれに配列の添え字を付けたものが使用されます(前者はcomponentDescriptors
のプロパティがobject
の場合、後者はobject
の配列だった場合に使用されます)
-
返値: Element
引数 componentDescriptor
に従って初期化された Element
。
例外
AggregateError
- 以下のいずれかの例外が発生した場合、それらを集約した
AggregateError
が発生します:TypeError
: 値componentDescriptor
が非null
のオブジェクトでなかった場合TypeError
: 値componentDescriptor.tagName
が文字列でなかった場合TypeError
: 値componentDescriptor.value
がnull
でも文字列でもなかった場合TypeError
: 値componentDescriptor.text
がnull
でも文字列でもなかった場合TypeError
: 値componentDescriptor.children
がnull
でも反復可能オブジェクト (iterable) でもなかった場合TypeError
: 値componentDescriptor.primary
がnull
でも文字列でもなかった場合TypeError
: 値componentDescriptor.activeEvents
がnull
でも文字列でも反復可能オブジェクト (iterable) でもなかった場合TypeError
: 値componentDescriptor.attributes
がnull
でも非null
オブジェクトでもなかった場合TypeError
: 記述子のプロパティtagName
がタグ名として正しくなかった場合TypeError
: 記述子のプロパティactiveEvents
が文字列でない成分を含んでいた場合TypeError
: 記述子のプロパティactiveEvents
が空文字列または空白のみからなる文字列を含んでいた場合TypeError
: 記述子のプロパティattributes
が空文字列または空白のみからなる文字列をキーとするプロパティを持っていた場合TypeError
: 記述子のプロパティattributes
がNaN
を値とするプロパティを持っていた場合TypeError
: 記述子のプロパティattributes
がSymbol
型の値のプロパティを持っていた場合TypeError
: 記述子のプロパティattributes
がfunction
型の値のプロパティを持っていた場合TypeError
: 記述子のプロパティchildren
がElement
でも文字列でも非null
のオブジェクトでもなかった場合
- 以下のいずれかの例外が発生した場合、それらを集約した
例
import { ProtoViewLogic } from "/alier_sys/ProtoViewLogic.js";
// <button> 要素を生成する
const button_ok = ProtoViewLogic.createElement({
tagName : "button",
value : "ok",
text : "OK",
activeEvents: "click",
attributes : { type: "button" }
});
// 生成した button_ok の内容を確認する
console.log(button_ok);
// ==> HTMLButtonElement
解説
与えられた引数 componentDescriptor
に従って、Element
を生成します。
note
- この関数は
ProtoViewLogic.createUiComponents()
の中で呼び出されます