Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Nov 23, 2020
2 parents 2729869 + d77bffb commit 23240e3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Signum Framework doesn't use any numeric versioning, since is distributed as sou

Whenever there are big changes worth to mention, we typicaly write it in the related commit. Here is the list of the relevant changes:

* [2020.11.13 IE Support?](https://github.com/signumsoftware/framework/commit/eb9b9f7cc550bcfd51c643133ebdf6dd73202aaa#commitcomment-44460763)
* [2020.11.13 Presenting Signum.Upgrade](https://github.com/signumsoftware/framework/commit/a1a37a4a8bd3291dd244daa0db7e113d5ce4f859#comments)
* [2020.11.13 Switch to .Net 5 and C# 9](https://github.com/signumsoftware/framework/commit/227a8e79aece9d3be5020f2a8dad840c4fba95ad#comments)
* [2020.09.29 Adding support for WebAuthn](https://github.com/signumsoftware/framework/commit/76c66b8a2416b13b74bc4aeba480369651e09645#comments)
Expand Down
35 changes: 31 additions & 4 deletions Signum.React/Scripts/Components/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface TextAreaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement

export default function TextArea(p: TextAreaProps) {

var textAreaRef = React.useRef<HTMLTextAreaElement | null | undefined>();

function handleResize(ta: HTMLTextAreaElement) {
ta.style.height = "0";
ta.style.height = ta.scrollHeight + 'px';
Expand All @@ -17,15 +19,27 @@ export default function TextArea(p: TextAreaProps) {

const { autoResize, innerRef, minHeight, ...props } = p;

const handleRef = React.useCallback((a: HTMLTextAreaElement | null) => {
a && handleResize(a);
innerRef && (typeof innerRef == "function" ? innerRef(a) : (innerRef as any).current = a);
const handleRef = React.useCallback((ta: HTMLTextAreaElement | null) => {
textAreaRef.current = ta;
if (ta && p.autoResize) {
if (ta.offsetParent != null)
handleResize(ta);
else
whenVisible(ta, visible => visible && handleResize(ta));
}
innerRef && (typeof innerRef == "function" ? innerRef(ta) : (innerRef as any).current = ta);
}, [innerRef, minHeight]);

React.useEffect(() => {
if (p.autoResize && textAreaRef.current && p.value != null)
handleResize(textAreaRef.current);
}, [p.value]);

return (
<textarea {...props} onInput={e => {
if (p.autoResize)
if (p.autoResize) {
handleResize(e.currentTarget);
}
if (p.onInput)
p.onInput(e);
}} style={
Expand All @@ -39,3 +53,16 @@ export default function TextArea(p: TextAreaProps) {

TextArea.defaultProps = { autoResize: true, minHeight: "50px" };

function whenVisible(element: HTMLElement, callback: (visible: boolean) => void) {
var options = {
root: document.documentElement
}

var observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
callback(entry.intersectionRatio > 0);
});
}, options);

observer.observe(element);
}
5 changes: 3 additions & 2 deletions Signum.React/Scripts/Lines/ValueLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,12 @@ ValueLineRenderers.renderers["TextArea" as ValueLineType] = (vl) => {
const s = vl.props;

var htmlAtts = vl.props.valueHtmlAttributes;
var autoResize = htmlAtts?.style?.height == null && htmlAtts?.rows == null;

if (s.ctx.readOnly)
return (
<FormGroup ctx={s.ctx} labelText={s.labelText} helpText={s.helpText} htmlAttributes={{ ...vl.baseHtmlAttributes(), ...s.formGroupHtmlAttributes }} labelHtmlAttributes={s.labelHtmlAttributes}>
<TextArea {...htmlAtts} className={addClass(htmlAtts, classes(s.ctx.formControlClass, vl.mandatoryClass))} value={s.ctx.value || ""}
<TextArea {...htmlAtts} autoResize={autoResize} className={addClass(htmlAtts, classes(s.ctx.formControlClass, vl.mandatoryClass))} value={s.ctx.value || ""}
disabled />
</FormGroup>
);
Expand All @@ -433,7 +434,7 @@ ValueLineRenderers.renderers["TextArea" as ValueLineType] = (vl) => {
return (
<FormGroup ctx={s.ctx} labelText={s.labelText} helpText={s.helpText} htmlAttributes={{ ...vl.baseHtmlAttributes(), ...s.formGroupHtmlAttributes }} labelHtmlAttributes={s.labelHtmlAttributes}>
{vl.withItemGroup(
<TextArea {...vl.props.valueHtmlAttributes} className={addClass(vl.props.valueHtmlAttributes, classes(s.ctx.formControlClass, vl.mandatoryClass))} value={s.ctx.value || ""}
<TextArea {...vl.props.valueHtmlAttributes} autoResize={autoResize} className={addClass(vl.props.valueHtmlAttributes, classes(s.ctx.formControlClass, vl.mandatoryClass))} value={s.ctx.value || ""}
onChange={isIE11() ? undefined : handleTextOnChange} //https://github.com/facebook/react/issues/7211 && https://github.com/omcljs/om/issues/704
onInput={isIE11() ? handleTextOnChange : undefined}
onBlur={handleBlur ?? htmlAtts?.onBlur}
Expand Down
2 changes: 1 addition & 1 deletion Signum.Upgrade/CodeUpgradeRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void Draw()
foreach (var upg in this.Upgrades)
{
ConsoleColor color = upg.IsExecuted ? ConsoleColor.DarkGreen :
upg == next ? ConsoleColor.Green :
upg == next ? ConsoleColor.Blue :
ConsoleColor.White;

SafeConsole.WriteColor(color,
Expand Down
14 changes: 14 additions & 0 deletions Signum.Upgrade/Upgrades/Upgrade_20201110_DotNet5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public override void Execute(UpgradeContext uctx)
replaceBy: @"protected override void ChildCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args)");
});



uctx.ForeachCodeFile("*.csproj", file =>
{
file.Replace(
Expand All @@ -39,6 +41,18 @@ public override void Execute(UpgradeContext uctx)
file.UpdateNugetReference(@"Microsoft.NET.Test.Sdk", @"16.8.0");
});

uctx.ChangeCodeFile("Southwind.Terminal/Program.cs", file =>
{
file.WarningLevel = WarningLevel.Warning;
file.Replace("BigStringMode.FileSystem", "BigStringMode.File");
});

uctx.ChangeCodeFile("Southwind.Logic/Starter.cs", file =>
{
file.WarningLevel = WarningLevel.Warning;
file.Replace("BigStringMode.FileSystem", "BigStringMode.File");
});

uctx.ChangeCodeFile($@"Southwind.React\Startup.cs", file =>
{
file.Replace("AddNewtonsoftJson", "AddJsonOptions");
Expand Down
19 changes: 11 additions & 8 deletions Signum.Upgrade/Upgrades/Upgrade_20201119_SplitPolyfills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,33 @@ class Upgrade_20201119_SplitPolyfills : CodeUpgradeBase

public override void Execute(UpgradeContext uctx)
{
uctx.ForeachCodeFile("Southwind.React/App/MainPublic.tsx", uctx.EntitiesDirectory, file =>
uctx.ChangeCodeFile("Southwind.React/Startup.cs", file =>
{
file.WarningLevel = WarningLevel.Warning;
file.RemoveAllLines(a => a.Contains("builder.UseETagger();"));
});

uctx.ChangeCodeFile("Southwind.React/App/MainPublic.tsx", file =>
{
file.WarningLevel = WarningLevel.None;
file.RemoveAllLines(a => a.Contains("WebAuthnClient.start({"));
});

uctx.ForeachCodeFile("Southwind.React/package.json", file =>
uctx.ChangeCodeFile("Southwind.React/package.json", file =>
{
file.Replace(
searchFor: @"&& webpack --config webpack.config.dll.js",
replaceBy: @"&& webpack --config webpack.config.polyfills.js && webpack --config webpack.config.dll.js");
});

uctx.ForeachCodeFile("Southwind.React/webpack.config.js", file =>
uctx.ChangeCodeFile("Southwind.React/webpack.config.js", file =>
{
file.Replace(
searchFor: @"""./App/polyfills.js"", ",
replaceBy:"");
});

uctx.CreateCodeFile("Southwind.React/webpack.config.js", @"var path = require(""path"");
uctx.CreateCodeFile("Southwind.React/webpack.config.polyfills.js", @"var path = require(""path"");
var webpack = require(""webpack"");
var AssetsPlugin = require('assets-webpack-plugin');
Expand Down Expand Up @@ -64,17 +70,14 @@ public override void Execute(UpgradeContext uctx)
}
};");

uctx.ForeachCodeFile("Southwind.React/Views/Home/Index.cshtml", file =>
uctx.ChangeCodeFile("Southwind.React/Views/Home/Index.cshtml", file =>
{
file.InsertAfterFirstLine(
a => a.Contains("var vendor = (string)JObject.Parse(jsonDll"),
@"
string jsonPolyfills = File.ReadAllText(System.IO.Path.Combine(hostingEnv.WebRootPath, ""dist/webpack-assets.polyfills.json""));
var polyfills = (string)JObject.Parse(jsonPolyfills).Property(""polyfills"")!.Value[""js""]!;");
});

uctx.ChangeCodeFile($@"Southwind.React\Startup.cs", file =>
{
file.InsertAfterFirstLine(a => a.Contains(@" var __baseUrl = ""@Url.Content(""~/"")"";"),
@"var browser = (function (agent) {
switch (true) {
Expand Down

0 comments on commit 23240e3

Please sign in to comment.