This is an automated email from the ASF dual-hosted git repository. thiagohp pushed a commit to branch feature/coffeescript-to-typescript in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
commit fb73230bfef398f8aba8b8c9a92b2c18366d3a8a Author: Thiago H. de Paula Figueiredo <[email protected]> AuthorDate: Sat May 24 15:45:58 2025 -0300 TAP5-2804: fixing onDocument() and its usages, plus imports --- .../t5/beanvalidator/beanvalidator-validation.ts | 9 +++++++- .../main/typescript/src/t5/core/ajaxformloop.ts | 9 ++++++-- .../src/main/typescript/src/t5/core/alert.ts | 4 +++- .../main/typescript/src/t5/core/confirm-click.ts | 12 +++++++++++ .../src/main/typescript/src/t5/core/datefield.ts | 4 +++- .../typescript/src/t5/core/exception-display.ts | 6 +++++- .../main/typescript/src/t5/core/exception-frame.ts | 4 +++- .../src/main/typescript/src/t5/core/fields.ts | 17 ++++++++++++--- .../main/typescript/src/t5/core/form-fragment.ts | 20 +++++++++++------ .../src/main/typescript/src/t5/core/forms.ts | 25 ++++++++++++++++------ .../src/main/typescript/src/t5/core/init.ts | 4 ++++ .../src/t5/core/t5-core-dom-prototype.ts | 2 +- .../src/main/typescript/src/t5/core/types.ts | 2 +- .../src/main/typescript/src/t5/core/validation.ts | 5 +++++ 14 files changed, 98 insertions(+), 25 deletions(-) diff --git a/tapestry-core/src/main/typescript/src/t5/beanvalidator/beanvalidator-validation.ts b/tapestry-core/src/main/typescript/src/t5/beanvalidator/beanvalidator-validation.ts index aa5779148..eb407fca4 100644 --- a/tapestry-core/src/main/typescript/src/t5/beanvalidator/beanvalidator-validation.ts +++ b/tapestry-core/src/main/typescript/src/t5/beanvalidator/beanvalidator-validation.ts @@ -24,8 +24,15 @@ import _ from "underscore"; import dom from "t5/core/dom" import events from "t5/core/events" +import fields from "t5/core/fields" import utils from "t5/core/utils" -import validation from "t5/core/validation"; +import validation from "t5/core/validation" + +// Both lines below are used to force the TypeScript compiler to actually import t5/core/fields +// and t5/core/validation even though they're not used directly here. This file uses events +// set up by the imported files. +let workaround1 = fields; +let workaround2 = validation; // @ts-ignore const rangeValue = function(element, attribute, defaultValue) { diff --git a/tapestry-core/src/main/typescript/src/t5/core/ajaxformloop.ts b/tapestry-core/src/main/typescript/src/t5/core/ajaxformloop.ts index ce5f8587d..7b13bb2ce 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/ajaxformloop.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/ajaxformloop.ts @@ -28,8 +28,10 @@ import { ElementWrapper, ResponseWrapper } from "t5/core/types"; const AFL_SELECTOR = "[data-container-type='core/AjaxFormLoop']"; const FRAGMENT_TYPE = "core/ajaxformloop-fragment"; -dom.onDocument("click", `${AFL_SELECTOR} [data-afl-behavior=remove]`, function(element: ElementWrapper) { +dom.onDocument("click", `${AFL_SELECTOR} [data-afl-behavior=remove]`, function() { + // @ts-ignore + let element: ElementWrapper = this; const afl = element.findParent(AFL_SELECTOR); if (!afl) { @@ -61,7 +63,10 @@ dom.onDocument("click", `${AFL_SELECTOR} [data-afl-behavior=remove]`, function(e return false; }); -dom.onDocument("click", `${AFL_SELECTOR} [data-afl-behavior=insert-before] [data-afl-trigger=add]`, function(element: ElementWrapper) { +dom.onDocument("click", `${AFL_SELECTOR} [data-afl-behavior=insert-before] [data-afl-trigger=add]`, function() { + + // @ts-ignore + let element: ElementWrapper = this; const afl = element.findParent(AFL_SELECTOR); diff --git a/tapestry-core/src/main/typescript/src/t5/core/alert.ts b/tapestry-core/src/main/typescript/src/t5/core/alert.ts index a4c05439b..d381e0b2c 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/alert.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/alert.ts @@ -101,7 +101,9 @@ const setupUI = function(outer: ElementWrapper) { return false; }); - return outer.on("click", "button.close", function(element: ElementWrapper) { + return outer.on("click", "button.close", function() { + // @ts-ignore + let element: ElementWrapper = this; dismissOne(outer, element); return false; }); diff --git a/tapestry-core/src/main/typescript/src/t5/core/confirm-click.ts b/tapestry-core/src/main/typescript/src/t5/core/confirm-click.ts index b722c8cef..1a804f036 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/confirm-click.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/confirm-click.ts @@ -1,3 +1,15 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http:#www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + /** * ## t5/core/confirm-click * diff --git a/tapestry-core/src/main/typescript/src/t5/core/datefield.ts b/tapestry-core/src/main/typescript/src/t5/core/datefield.ts index b4ab62201..c95abf07f 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/datefield.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/datefield.ts @@ -65,7 +65,9 @@ let activePopup: ElementWrapper | null = null; const isPartOfPopup = (element: ElementWrapper) => (element.findParent(".labelPopup") != null) || (element.findParent(".datefield-popup") != null); -dom.body.on("click", null, function(element: ElementWrapper) { +dom.body.on("click", null, function() { + // @ts-ignore + let element: ElementWrapper = this; if (activePopup && !isPartOfPopup(element)) { activePopup.hide(); activePopup = null; diff --git a/tapestry-core/src/main/typescript/src/t5/core/exception-display.ts b/tapestry-core/src/main/typescript/src/t5/core/exception-display.ts index 39979729c..75a76d9ec 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/exception-display.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/exception-display.ts @@ -21,7 +21,11 @@ import dom from "t5/core/dom"; import { ElementWrapper } from "t5/core/types"; -dom.onDocument("click", "[data-behavior=stack-trace-filter-toggle]", function(element: ElementWrapper) { +dom.onDocument("click", "[data-behavior=stack-trace-filter-toggle]", function() { + + // @ts-ignore + let element: ElementWrapper = this; + const checked = element.checked(); for (var traceList of Array.from(dom.body.find(".stack-trace"))) { diff --git a/tapestry-core/src/main/typescript/src/t5/core/exception-frame.ts b/tapestry-core/src/main/typescript/src/t5/core/exception-frame.ts index d6f6f2153..ad2508cfa 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/exception-frame.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/exception-frame.ts @@ -40,7 +40,9 @@ const write = function(container: ElementWrapper, content: AddableContent) { return iframeDocument!.close(); }; -const clear = function(element: ElementWrapper) { +const clear = function() { + // @ts-ignore + let element: ElementWrapper = this; const container = element.closest('.exception-container'); container!.remove(); return false; diff --git a/tapestry-core/src/main/typescript/src/t5/core/fields.ts b/tapestry-core/src/main/typescript/src/t5/core/fields.ts index badcab15e..ba4c24005 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/fields.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/fields.ts @@ -27,6 +27,10 @@ import utils from "t5/core/utils"; import forms from "t5/core/forms"; import { ElementWrapper, EventWrapper } from "t5/core/types"; +// Line below is used to force the TypeScript compiler to actually import t5/core/forms */ +// as it's not used directly here. This file uses events set up by the imported files. +let workaround = forms; + let exports_; const ensureFieldId = function(field: ElementWrapper): string { let fieldId = field.attr("id"); @@ -116,7 +120,10 @@ const collectOptionValues = (wrapper: ElementWrapper) => _.pluck(wrapper.element // Default registrations: -dom.onDocument(events.field.inputValidation, null, function(element: ElementWrapper, event: EventWrapper, formMemo: any) { +dom.onDocument(events.field.inputValidation, null, function(event: EventWrapper, formMemo: any) { + + // @ts-ignore + let element: ElementWrapper = this; // Fields that are disabled, or not visible to the user are not subject to // validation. Typically, a field will only be invisible due to the @@ -187,7 +194,9 @@ dom.onDocument(events.field.inputValidation, null, function(element: ElementWrap }); -dom.onDocument(events.field.clearValidationError, null, function(element: ElementWrapper) { +dom.onDocument(events.field.clearValidationError, null, function() { + // @ts-ignore + let element: ElementWrapper = this; const blocks = findHelpBlocks(element); for (var block of Array.from(blocks || [])) { @@ -202,7 +211,9 @@ dom.onDocument(events.field.clearValidationError, null, function(element: Elemen }); -dom.onDocument(events.field.showValidationError, null, function(element: ElementWrapper, event: EventWrapper, memo: any) { +dom.onDocument(events.field.showValidationError, null, function(event: EventWrapper, memo: any) { + // @ts-ignore + let element: ElementWrapper = this; let blocks = findHelpBlocks(element); if (!blocks) { diff --git a/tapestry-core/src/main/typescript/src/t5/core/form-fragment.ts b/tapestry-core/src/main/typescript/src/t5/core/form-fragment.ts index 02082f288..efe6cff8c 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/form-fragment.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/form-fragment.ts @@ -21,6 +21,10 @@ import events from "t5/core/events"; import forms from "t5/core/forms"; import { ElementWrapper, EventWrapper }from "t5/core/types"; +// Line below is used to force the TypeScript compiler to actually import t5/core/forms +// as it's not used directly here. This file uses events set up by the imported files. +let workaround = forms; + const SELECTOR = "[data-component-type='core/FormFragment']"; const REENABLE = "data-re-enable-when-fragment-visible"; @@ -60,16 +64,20 @@ const updateFields = function(fragment: ElementWrapper, makeVisible: boolean) { // because of the didShow/didHide events ... but we're really just seeing the evolution // from the old style (the FormFragment class as controller) to the new style (DOM events and // top-level event handlers). -dom.onDocument(events.formfragment.changeVisibility, SELECTOR, function(element: ElementWrapper, event: EventWrapper) { - const makeVisible = event.memo.visible; +dom.onDocument(events.formfragment.changeVisibility, SELECTOR, function(event: EventWrapper) { + + // @ts-ignore + let element: ElementWrapper = this; + + const makeVisible = event.memo.visible; - element[makeVisible ? "show" : "hide"](); + element[makeVisible ? "show" : "hide"](); - updateFields(element, makeVisible); + updateFields(element, makeVisible); - element.trigger(events.element[makeVisible ? "didShow" : "didHide"]); + element.trigger(events.element[makeVisible ? "didShow" : "didHide"]); - return false; + return false; }); // When a FormFragment is initially rendered as hidden, then we need to do some diff --git a/tapestry-core/src/main/typescript/src/t5/core/forms.ts b/tapestry-core/src/main/typescript/src/t5/core/forms.ts index f9eeb3d1b..1a3ea8099 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/forms.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/forms.ts @@ -21,7 +21,7 @@ import events from "t5/core/events"; import dom from "t5/core/dom"; import _ from "underscore"; -import { ElementWrapper }from "t5/core/types"; +import { ElementWrapper } from "t5/core/types"; // Meta-data name that indicates the next submission should skip validation (typically, because // the form was submitted by a "cancel" button). @@ -127,7 +127,10 @@ const gatherParameters = function(form: ElementWrapper) { }; -const defaultValidateAndSubmit = function(element: ElementWrapper) { +const defaultValidateAndSubmit = function() { + + // @ts-ignore + let element = this; let where = () => "processing form submission"; @@ -144,7 +147,10 @@ const defaultValidateAndSubmit = function(element: ElementWrapper) { for (var field of Array.from(element.find("[data-validation]"))) { memo = {} as any; + // @ts-ignore where = () => `triggering ${events.field.inputValidation} event on ${field.toString()}`; + + // @ts-ignore field.trigger(events.field.inputValidation, memo); if (memo.error) { @@ -168,6 +174,7 @@ const defaultValidateAndSubmit = function(element: ElementWrapper) { // If a specific field has been identified as the source of the validation error, then // focus on it. + // @ts-ignore if (focusField) { focusField.focus(); } // Trigger an event to inform that form validation results in error @@ -204,14 +211,18 @@ dom.onDocument("submit", TAPESTRY_CORE_FORM_SELECTOR, defaultValidateAndSubmit); // was responsible for the eventual submit; this is very important to Ajax updates, otherwise the // information about which control triggered the submit gets lost. dom.onDocument("click", TAPESTRY_CORE_FORM_SELECTOR + " input[type=submit], " + TAPESTRY_CORE_FORM_SELECTOR + " input[type=image]", - function(element: ElementWrapper) { - const form = element.element as HTMLInputElement; - setSubmittingHidden((dom(form)!), element); -}); + function() { + // @ts-ignore + setSubmittingHidden(dom(this.element.form), this); + } +); // Support for link submits. `data-submit-mode` will be non-null, possibly "cancel". // Update the hidden field, but also cancel the default behavior for the click. -dom.onDocument("click", "a[data-submit-mode]", function(element: ElementWrapper) { +dom.onDocument("click", "a[data-submit-mode]", function() { + + // @ts-ignore + let element: ElementWrapper = this; const form = element.findParent("form"); if (!form) { diff --git a/tapestry-core/src/main/typescript/src/t5/core/init.ts b/tapestry-core/src/main/typescript/src/t5/core/init.ts index b047f0fe5..cbd4636a6 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/init.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/init.ts @@ -20,6 +20,10 @@ */ import console from "t5/core/console"; +// Line below is used to force the TypeScript compiler to actually import t5/core/console */ +// as the compiler doesn't seet to notice it's used directly here.. +let workaround = console; + export default (console: { error: (arg0: string) => any; }) => // Exports a single function that finds an initializer in `T5.initializers` and invokes it. function(initName: string | number, ...args: any) { // @ts-ignore diff --git a/tapestry-core/src/main/typescript/src/t5/core/t5-core-dom-prototype.ts b/tapestry-core/src/main/typescript/src/t5/core/t5-core-dom-prototype.ts index 67334457d..ee4dd9ed3 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/t5-core-dom-prototype.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/t5-core-dom-prototype.ts @@ -120,7 +120,7 @@ const onevent = function(elements: HTMLElement[], eventNames: string[], match: s // @ts-ignore eventWrapper = new PrototypeEventWrapper(prototypeEvent); // @ts-ignore - result = prototypeEvent.stopped ? false : handler.call(elementWrapper.element, elementWrapper, eventWrapper, eventWrapper.memo); + result = prototypeEvent.stopped ? false : handler.call(elementWrapper, eventWrapper, eventWrapper.memo); if (result === false) { prototypeEvent.stop(); } diff --git a/tapestry-core/src/main/typescript/src/t5/core/types.ts b/tapestry-core/src/main/typescript/src/t5/core/types.ts index 5f0af6eae..1cb287fc8 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/types.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/types.ts @@ -25,7 +25,7 @@ export interface IEventWrapper { /** * Type of event handlers functions. */ -export type OnEventHandler = (element: ElementWrapper, event: EventWrapper, memo: any) => any; +export type OnEventHandler = (event: EventWrapper, memo: any) => any; /** * Class defining the offset of an element. diff --git a/tapestry-core/src/main/typescript/src/t5/core/validation.ts b/tapestry-core/src/main/typescript/src/t5/core/validation.ts index 721333c60..39d47c5ab 100644 --- a/tapestry-core/src/main/typescript/src/t5/core/validation.ts +++ b/tapestry-core/src/main/typescript/src/t5/core/validation.ts @@ -22,8 +22,13 @@ import dom from "t5/core/dom"; import events from "t5/core/events"; import utils from "t5/core/utils"; import messages from "t5/core/messages"; +import fields from "t5/core/fields"; import { ElementWrapper } from "t5/core/types"; +// Line below is used to force the TypeScript compiler to actually import t5/core/fields +// as it's not used directly here. This file uses events set up by the imported files. +let workaround = fields; + const REGEXP_META = "t5:regular-expression"; const minus = messages("decimal-symbols.minus");
