Skip to content

Commit df35836

Browse files
authored
Expose DOM element ReactComponents (#110)
* Expose DOM element ReactComponents * Remove duplicate 'svg' definition
1 parent a81de99 commit df35836

File tree

7 files changed

+1570
-519
lines changed

7 files changed

+1570
-519
lines changed

Diff for: Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
all: build examples
2+
3+
build: bower_components node_modules
4+
npm run build
5+
6+
bower_components: node_modules
7+
npx bower --allow-root install
8+
9+
node_modules:
10+
npm install
11+
12+
.PHONY: build

Diff for: codegen/index.js

+22-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Data.Nullable (Nullable)
1414
import Foreign.Object (Object)
1515
import Prim.Row (class Union)
1616
import Web.DOM (Node)
17-
import React.Basic (JSX, Ref, element)
17+
import React.Basic (JSX, ReactComponent, Ref, element)
1818
import React.Basic.DOM.Internal (CSS, unsafeCreateDOMComponent)
1919
import React.Basic.Events (EventHandler)
2020
@@ -38,9 +38,11 @@ const svgHeader = `-- | ----------------------------------------
3838
3939
module React.Basic.DOM.SVG where
4040
41+
import Data.Nullable (Nullable)
4142
import Foreign.Object (Object)
4243
import Prim.Row (class Union)
43-
import React.Basic (JSX, element)
44+
import Web.DOM (Node)
45+
import React.Basic (JSX, ReactComponent, Ref, element)
4446
import React.Basic.DOM.Internal (SharedSVGProps, unsafeCreateDOMComponent)
4547
4648
`;
@@ -69,20 +71,8 @@ Object.keys(svgProps).forEach(elName => {
6971
// The attribute list for <svg> in react-html-attributes
7072
// is wrong (it contains the union of the attributes of all
7173
// svg elements)
72-
htmlProps['svg'] = camelCaseSvgProps['svg'].concat([
73-
"xlinkActuate",
74-
"xlinkArcrole",
75-
"xlinkHref",
76-
"xlinkRole",
77-
"xlinkShow",
78-
"xlinkTitle",
79-
"xlinkType",
80-
"xmlBase",
81-
"xmlLang",
82-
"xmlSpace",
83-
"xmlns",
84-
"xmlnsXlink"
85-
]);
74+
delete htmlProps.elements.html[htmlProps.elements.html.indexOf("svg")];
75+
delete htmlProps["svg"];
8676

8777
const printRecord = (e, elProps) =>
8878
elProps.length
@@ -91,7 +81,9 @@ const printRecord = (e, elProps) =>
9181
)`
9282
: "()";
9383

94-
const generatePropTypes = (elements, props, sharedPropType) =>
84+
const reactProps = ["ref", "key", "_data"];
85+
86+
const generatePropTypes = (elements, props, sharedPropType) =>
9587
elements.map(e => {
9688
const noChildren = voids.includes(e);
9789
const symbol = reserved.includes(e) ? `${e}'` : e;
@@ -100,15 +92,26 @@ const generatePropTypes = (elements, props, sharedPropType) =>
10092

10193
return `
10294
type Props_${e} =${printRecord(e,
103-
(noChildren ? [] : ["children", "_data"]).concat(props[e] || [], props["*"] || []).sort()
95+
( noChildren
96+
? reactProps
97+
: reactProps.concat("children")
98+
)
99+
.concat(props[e] || [], props["*"] || [])
100+
.sort()
104101
)}
105102
106103
${symbol}
107104
:: forall attrs attrs_
108105
. Union attrs attrs_ ${propType}
109106
=> Record attrs
110107
-> JSX
111-
${symbol} = element (unsafeCreateDOMComponent "${e}")${
108+
${symbol} = element ${symbol}'
109+
110+
${symbol}'
111+
:: forall attrs attrs_
112+
. Union attrs attrs_ ${propType}
113+
=> ReactComponent (Record attrs)
114+
${symbol}' = unsafeCreateDOMComponent "${e}"${
112115
noChildren
113116
? ""
114117
: `

Diff for: codegen/react-html-attributes.json

-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"itemRef",
4545
"itemScope",
4646
"itemType",
47-
"key",
4847
"keyParams",
4948
"keyType",
5049
"lang",
@@ -109,7 +108,6 @@
109108
"property",
110109
"radioGroup",
111110
"readOnly",
112-
"ref",
113111
"resource",
114112
"role",
115113
"rowSpan",

Diff for: src/React/Basic.purs

-6
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,6 @@ foreign import fragment :: Array JSX -> JSX
301301

302302
-- | Create a `JSX` node from a `ReactComponent`, by providing the props.
303303
-- |
304-
-- | This function is for non-React-Basic React components, such as those
305-
-- | imported from FFI.
306-
-- |
307304
-- | __*See also:* `ReactComponent`, `elementKeyed`__
308305
element
309306
:: forall props
@@ -314,9 +311,6 @@ element = runFn2 element_
314311

315312
-- | Create a `JSX` node from a `ReactComponent`, by providing the props and a key.
316313
-- |
317-
-- | This function is for non-React-Basic React components, such as those
318-
-- | imported from FFI.
319-
-- |
320314
-- | __*See also:* `ReactComponent`, `element`, React's documentation regarding the special `key` prop__
321315
elementKeyed
322316
:: forall props

Diff for: src/React/Basic/DOM.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Effect (Effect)
2828
import Effect.Exception (Error, throw, try)
2929
import Effect.Uncurried (EffectFn1, EffectFn3, runEffectFn1, runEffectFn3)
3030
import React.Basic (ReactComponentInstance, JSX)
31-
import React.Basic.DOM.Generated (Props_a, Props_abbr, Props_address, Props_area, Props_article, Props_aside, Props_audio, Props_b, Props_base, Props_bdi, Props_bdo, Props_blockquote, Props_body, Props_br, Props_button, Props_canvas, Props_caption, Props_cite, Props_code, Props_col, Props_colgroup, Props_data, Props_datalist, Props_dd, Props_del, Props_details, Props_dfn, Props_dialog, Props_div, Props_dl, Props_dt, Props_em, Props_embed, Props_fieldset, Props_figcaption, Props_figure, Props_footer, Props_form, Props_h1, Props_h2, Props_h3, Props_h4, Props_h5, Props_h6, Props_head, Props_header, Props_hgroup, Props_hr, Props_html, Props_i, Props_iframe, Props_img, Props_input, Props_ins, Props_kbd, Props_keygen, Props_label, Props_legend, Props_li, Props_link, Props_main, Props_map, Props_mark, Props_math, Props_menu, Props_menuitem, Props_meta, Props_meter, Props_nav, Props_noscript, Props_object, Props_ol, Props_optgroup, Props_option, Props_output, Props_p, Props_param, Props_picture, Props_pre, Props_progress, Props_q, Props_rb, Props_rp, Props_rt, Props_rtc, Props_ruby, Props_s, Props_samp, Props_script, Props_section, Props_select, Props_slot, Props_small, Props_source, Props_span, Props_strong, Props_style, Props_sub, Props_summary, Props_sup, Props_svg, Props_table, Props_tbody, Props_td, Props_template, Props_textarea, Props_tfoot, Props_th, Props_thead, Props_time, Props_title, Props_tr, Props_track, Props_u, Props_ul, Props_var, Props_video, Props_wbr, a, a_, abbr, abbr_, address, address_, area, article, article_, aside, aside_, audio, audio_, b, b_, base, bdi, bdi_, bdo, bdo_, blockquote, blockquote_, body, body_, br, button, button_, canvas, canvas_, caption, caption_, cite, cite_, code, code_, col, colgroup, colgroup_, data', data_, datalist, datalist_, dd, dd_, del, del_, details, details_, dfn, dfn_, dialog, dialog_, div, div_, dl, dl_, dt, dt_, em, em_, embed, fieldset, fieldset_, figcaption, figcaption_, figure, figure_, footer, footer_, form, form_, h1, h1_, h2, h2_, h3, h3_, h4, h4_, h5, h5_, h6, h6_, head, head_, header, header_, hgroup, hgroup_, hr, html, html_, i, i_, iframe, iframe_, img, input, ins, ins_, kbd, kbd_, keygen, keygen_, label, label_, legend, legend_, li, li_, link, main, main_, map, map_, mark, mark_, math, math_, menu, menu_, menuitem, menuitem_, meta, meter, meter_, nav, nav_, noscript, noscript_, object, object_, ol, ol_, optgroup, optgroup_, option, option_, output, output_, p, p_, param, picture, picture_, pre, pre_, progress, progress_, q, q_, rb, rb_, rp, rp_, rt, rt_, rtc, rtc_, ruby, ruby_, s, s_, samp, samp_, script, script_, section, section_, select, select_, slot, slot_, small, small_, source, span, span_, strong, strong_, style, style_, sub, sub_, summary, summary_, sup, sup_, svg, svg_, table, table_, tbody, tbody_, td, td_, template, template_, textarea, textarea_, tfoot, tfoot_, th, th_, thead, thead_, time, time_, title, title_, tr, tr_, track, u, u_, ul, ul_, var, var_, video, video_, wbr) as Generated
31+
import React.Basic.DOM.Generated (Props_a, Props_abbr, Props_address, Props_area, Props_article, Props_aside, Props_audio, Props_b, Props_base, Props_bdi, Props_bdo, Props_blockquote, Props_body, Props_br, Props_button, Props_canvas, Props_caption, Props_cite, Props_code, Props_col, Props_colgroup, Props_data, Props_datalist, Props_dd, Props_del, Props_details, Props_dfn, Props_dialog, Props_div, Props_dl, Props_dt, Props_em, Props_embed, Props_fieldset, Props_figcaption, Props_figure, Props_footer, Props_form, Props_h1, Props_h2, Props_h3, Props_h4, Props_h5, Props_h6, Props_head, Props_header, Props_hgroup, Props_hr, Props_html, Props_i, Props_iframe, Props_img, Props_input, Props_ins, Props_kbd, Props_keygen, Props_label, Props_legend, Props_li, Props_link, Props_main, Props_map, Props_mark, Props_math, Props_menu, Props_menuitem, Props_meta, Props_meter, Props_nav, Props_noscript, Props_object, Props_ol, Props_optgroup, Props_option, Props_output, Props_p, Props_param, Props_picture, Props_pre, Props_progress, Props_q, Props_rb, Props_rp, Props_rt, Props_rtc, Props_ruby, Props_s, Props_samp, Props_script, Props_section, Props_select, Props_slot, Props_small, Props_source, Props_span, Props_strong, Props_style, Props_sub, Props_summary, Props_sup, Props_table, Props_tbody, Props_td, Props_template, Props_textarea, Props_tfoot, Props_th, Props_thead, Props_time, Props_title, Props_tr, Props_track, Props_u, Props_ul, Props_var, Props_video, Props_wbr, a, a', a_, abbr, abbr', abbr_, address, address', address_, area, area', article, article', article_, aside, aside', aside_, audio, audio', audio_, b, b', b_, base, base', bdi, bdi', bdi_, bdo, bdo', bdo_, blockquote, blockquote', blockquote_, body, body', body_, br, br', button, button', button_, canvas, canvas', canvas_, caption, caption', caption_, cite, cite', cite_, code, code', code_, col, col', colgroup, colgroup', colgroup_, data', data'', data_, datalist, datalist', datalist_, dd, dd', dd_, del, del', del_, details, details', details_, dfn, dfn', dfn_, dialog, dialog', dialog_, div, div', div_, dl, dl', dl_, dt, dt', dt_, em, em', em_, embed, embed', fieldset, fieldset', fieldset_, figcaption, figcaption', figcaption_, figure, figure', figure_, footer, footer', footer_, form, form', form_, h1, h1', h1_, h2, h2', h2_, h3, h3', h3_, h4, h4', h4_, h5, h5', h5_, h6, h6', h6_, head, head', head_, header, header', header_, hgroup, hgroup', hgroup_, hr, hr', html, html', html_, i, i', i_, iframe, iframe', iframe_, img, img', input, input', ins, ins', ins_, kbd, kbd', kbd_, keygen, keygen', keygen_, label, label', label_, legend, legend', legend_, li, li', li_, link, link', main, main', main_, map, map', map_, mark, mark', mark_, math, math', math_, menu, menu', menu_, menuitem, menuitem', menuitem_, meta, meta', meter, meter', meter_, nav, nav', nav_, noscript, noscript', noscript_, object, object', object_, ol, ol', ol_, optgroup, optgroup', optgroup_, option, option', option_, output, output', output_, p, p', p_, param, param', picture, picture', picture_, pre, pre', pre_, progress, progress', progress_, q, q', q_, rb, rb', rb_, rp, rp', rp_, rt, rt', rt_, rtc, rtc', rtc_, ruby, ruby', ruby_, s, s', s_, samp, samp', samp_, script, script', script_, section, section', section_, select, select', select_, slot, slot', slot_, small, small', small_, source, source', span, span', span_, strong, strong', strong_, style, style', style_, sub, sub', sub_, summary, summary', summary_, sup, sup', sup_, table, table', table_, tbody, tbody', tbody_, td, td', td_, template, template', template_, textarea, textarea', textarea_, tfoot, tfoot', tfoot_, th, th', th_, thead, thead', thead_, time, time', time_, title, title', title_, tr, tr', tr_, track, track', u, u', u_, ul, ul', ul_, var, var', var_, video, video', video_, wbr, wbr') as Generated
3232
import React.Basic.DOM.Internal (CSS, css, mergeStyles, unsafeCreateDOMComponent) as Internal
3333
import Unsafe.Coerce (unsafeCoerce)
3434
import Web.DOM (Element, Node)

0 commit comments

Comments
 (0)