From 43a71aa26ea72b87b41dbd06fdfa1f84385bb7b9 Mon Sep 17 00:00:00 2001 From: hariroshan Date: Wed, 18 Jan 2023 13:12:31 +0530 Subject: [PATCH] added prefixing within constants --- elm-native-js/src/Native/Constants.res | 152 +++++++++++------- elm-native-js/src/Native/Elements.res | 4 +- elm-native-js/src/Native/NativescriptCore.res | 6 +- 3 files changed, 95 insertions(+), 67 deletions(-) diff --git a/elm-native-js/src/Native/Constants.res b/elm-native-js/src/Native/Constants.res index 23bcf1e..0ae75d8 100644 --- a/elm-native-js/src/Native/Constants.res +++ b/elm-native-js/src/Native/Constants.res @@ -9,6 +9,9 @@ let dashed: string => string = %raw(` return str.replace(/[A-Z]/g, m => "-" + m.toLowerCase()); } `) + +let prefixWithBind = arr => Belt.Array.concat(arr, arr->Belt.Array.map(x => `bind-${x}`)) + /* copy(Array.from(temp1.children).map(x => x.innerText).filter(x => !(x.startsWith('_') || x.endsWith("Event"))).filter(x => !textBase.includes(x))) */ let view: array = [ @@ -126,16 +129,21 @@ let view: array = "visibility", "width", "key", - ]->Belt.Array.map(dashed) + ] + ->Belt.Array.map(dashed) + ->prefixWithBind let paddings: array = - ["padding", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop"]->Belt.Array.map(dashed) + ["padding", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop"] + ->Belt.Array.map(dashed) + ->prefixWithBind + ->prefixWithBind let layoutBase: array = [ view, paddings, - ["clipToBounds", "isPassThroughParentEnabled"]->Belt.Array.map(dashed), + ["clipToBounds", "isPassThroughParentEnabled"]->Belt.Array.map(dashed)->prefixWithBind, ]->Belt.Array.concatMany let textBase: array = @@ -157,33 +165,35 @@ let textBase: array = "textTransform", "whiteSpace", "textWrap", - ]->Belt.Array.map(dashed), + ] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany let dockLayout: array = - [layoutBase, ["stretchLastChild"]->Belt.Array.map(dashed)]->Belt.Array.concatMany + [layoutBase, ["stretchLastChild"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let gridLayout: array = - [ - layoutBase, - ["columns", "rows"]->Belt.Array.map(dashed), - ]->Belt.Array.concatMany + [layoutBase, ["columns", "rows"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let stackLayout: array = - [layoutBase, ["orientation"]->Belt.Array.map(dashed)]->Belt.Array.concatMany + [layoutBase, ["orientation"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let wrapLayout: array = - [stackLayout, ["itemHeight", "itemWidth"]->Belt.Array.map(dashed)]->Belt.Array.concatMany + [ + stackLayout, + ["itemHeight", "itemWidth"]->Belt.Array.map(dashed)->prefixWithBind, + ]->Belt.Array.concatMany let flexboxLayout: array = [ layoutBase, - ["alignContent", "alignItems", "flexDirection", "flexWrap", "justifyContent"]->Belt.Array.map( - dashed, - ), + ["alignContent", "alignItems", "flexDirection", "flexWrap", "justifyContent"] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany -let button = [textBase, ["textWrap"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let button = [textBase, ["textWrap"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let frameBase = [ @@ -194,7 +204,9 @@ let frameBase = "transition", "defaultAnimatedNavigation", "defaultTransition", - ]->Belt.Array.map(dashed), + ] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany let pageBase = @@ -207,35 +219,33 @@ let pageBase = "backgroundSpanUnderStatusBar", "enableSwipeBackNavigation", "statusBarStyle", - ]->Belt.Array.map(dashed), + ] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany -let activityIndicator = [view, ["busy"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let activityIndicator = + [view, ["busy"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany /* for simplicity using view instead of viewBase */ let formattedString = [ view, - ["fontStyle", "style", "fontFamily", "fontWeight"]->Belt.Array.map(dashed), + ["fontStyle", "style", "fontFamily", "fontWeight"]->Belt.Array.map(dashed)->prefixWithBind, ]->Belt.Array.concatMany -let span = [formattedString, ["text"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let span = + [formattedString, ["text"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let datePicker = [ view, - [ - "date", - "day", - "iosPreferredDatePickerStyle", - "maxDate", - "minDate", - "month", - "year", - ]->Belt.Array.map(dashed), + ["date", "day", "iosPreferredDatePickerStyle", "maxDate", "minDate", "month", "year"] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany -let htmlView = [view, ["html"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let htmlView = [view, ["html"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let image = [ @@ -249,12 +259,16 @@ let image = "src", "stretch", "tintColor", - ]->Belt.Array.map(dashed), + ] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany -let listPicker = [view, ["selectedIndex"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let listPicker = + [view, ["selectedIndex"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany -let progress = [view, ["maxValue", "value"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let progress = + [view, ["maxValue", "value"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let scrollView = [ @@ -267,27 +281,36 @@ let scrollView = "scrollableHeight", "scrollableWidth", "verticalOffset", - ]->Belt.Array.map(dashed), + ] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany let searchBar = [ view, - ["hint", "text", "textFieldBackgroundColor", "textFieldHintColor"]->Belt.Array.map(dashed), + ["hint", "text", "textFieldBackgroundColor", "textFieldHintColor"] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany -let segmentedBarItem = [view, ["title"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let segmentedBarItem = + [view, ["title"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let segmentedBar = [ view, - ["selectedBackgroundColor", "selectedIndex"]->Belt.Array.map(dashed), + ["selectedBackgroundColor", "selectedIndex"]->Belt.Array.map(dashed)->prefixWithBind, ]->Belt.Array.concatMany let slider = - [view, ["value", "minValue", "maxValue"]->Belt.Array.map(dashed)]->Belt.Array.concatMany + [ + view, + ["value", "minValue", "maxValue"]->Belt.Array.map(dashed)->prefixWithBind, + ]->Belt.Array.concatMany -let switchComponent = [view, ["checked"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let switchComponent = + [view, ["checked"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let tabView = [ @@ -303,13 +326,15 @@ let tabView = "tabBackgroundColor", "tabTextColor", "tabTextFontSize", - ]->Belt.Array.map(dashed), + ] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany let tabViewItem = [ view, - ["canBeLoaded", "iconSource", "textTransform", "title"]->Belt.Array.map(dashed), + ["canBeLoaded", "iconSource", "textTransform", "title"]->Belt.Array.map(dashed)->prefixWithBind, ]->Belt.Array.concatMany let commonTextBase = @@ -335,18 +360,25 @@ let commonTextBase = "textTransform", "updateTextTrigger", "whiteSpace", - ]->Belt.Array.map(dashed) + ] + ->Belt.Array.map(dashed) + ->prefixWithBind let textField = [ view, paddings, commonTextBase, - ["closeOnReturn", "secure", "secureWithoutAutofill"]->Belt.Array.map(dashed), + ["closeOnReturn", "secure", "secureWithoutAutofill"]->Belt.Array.map(dashed)->prefixWithBind, ]->Belt.Array.concatMany let textView = - [view, paddings, commonTextBase, ["maxLines"]->Belt.Array.map(dashed)]->Belt.Array.concatMany + [ + view, + paddings, + commonTextBase, + ["maxLines"]->Belt.Array.map(dashed)->prefixWithBind, + ]->Belt.Array.concatMany let timePicker = [ @@ -361,25 +393,26 @@ let timePicker = "minute", "minuteInterval", "time", - ]->Belt.Array.map(dashed), + ] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany let webView = - [view, ["canGoBack", "canGoForward", "src"]->Belt.Array.map(dashed)]->Belt.Array.concatMany + [ + view, + ["canGoBack", "canGoForward", "src"]->Belt.Array.map(dashed)->prefixWithBind, + ]->Belt.Array.concatMany -let actionBar = [view, ["title", "flat"]->Belt.Array.map(dashed)]->Belt.Array.concatMany +let actionBar = + [view, ["title", "flat"]->Belt.Array.map(dashed)->prefixWithBind]->Belt.Array.concatMany let actionItem = [ view, - [ - "text", - "icon", - "ios.position", - "android.position", - "ios.systemIcon", - "android.systemIcon", - ]->Belt.Array.map(dashed), + ["text", "icon", "ios.position", "android.position", "ios.systemIcon", "android.systemIcon"] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany let navigationButton = actionItem @@ -387,12 +420,9 @@ let navigationButton = actionItem let listView = [ view, - [ - "itemTemplateSelector", - "iosEstimatedRowHeight", - "rowHeight", - "separatorColor", - ]->Belt.Array.map(dashed), + ["itemTemplateSelector", "iosEstimatedRowHeight", "rowHeight", "separatorColor"] + ->Belt.Array.map(dashed) + ->prefixWithBind, ]->Belt.Array.concatMany // Js.log("****************************") diff --git a/elm-native-js/src/Native/Elements.res b/elm-native-js/src/Native/Elements.res index 803b83e..b2a5c84 100644 --- a/elm-native-js/src/Native/Elements.res +++ b/elm-native-js/src/Native/Elements.res @@ -3,15 +3,13 @@ let makeRender = helperAdd => helperAdd(. current.parentElement, current) ) -let prefixWithBind = arr => Belt.Array.concat(arr, arr->Belt.Array.map(x => `bind-${x}`)) - let buildHandler: ( unit => Types.nativeObject, array, Js.Nullable.t<(. Types.htmlElement, Types.nativeObject) => unit>, ) => Types.handler = (new, observedAttributes, render) => { init: (. ()) => new(), - observedAttributes: prefixWithBind(observedAttributes), + observedAttributes, render, handlerKind: Types.Element, update: NativescriptCore.update, diff --git a/elm-native-js/src/Native/NativescriptCore.res b/elm-native-js/src/Native/NativescriptCore.res index 8bf4ef4..79e8232 100644 --- a/elm-native-js/src/Native/NativescriptCore.res +++ b/elm-native-js/src/Native/NativescriptCore.res @@ -26,9 +26,9 @@ module Application = { ( Constants.camelCased(extracted), // Allows expression binding only when attribute is prefixed. - if extracted != attr && assignmentKind == Types.BindingExpression { - newValue - // Global Eval expression is skipped to prevent user from executing JS + if assignmentKind == Types.BindingExpression { + extracted != attr ? newValue : (value, Types.String) + // Global Eval expression is skipped to prevent user from executing JS } else if attr == "text" && assignmentKind == Types.GlobalEvalExpression { (value, Types.String) } else {