@@ -52,6 +52,7 @@ const triggers = {
5252 * @callback saveTrigger
5353 * @param {Object } optionValue the value of the changed option
5454 * @param {string } option the name of the option that has been changed
55+ * @param {Event } event the event (input or change) that triggered saving
5556 * @return {Promise } optionally, to use await
5657 */
5758
@@ -69,6 +70,7 @@ const triggers = {
6970 * @param {string } param.option the name of the option that has been changed
7071 * @param {Array } param.saveTriggerValues all values returned by potentially
7172 * previously run save triggers
73+ * @param {Event } param.event the event (input or change) that triggered saving
7274 * @returns {Promise } recommend
7375 * @throws {Error } if saving e.g. fails, this will automatically trigger a generic
7476 * error to be shown in the UI
@@ -111,10 +113,11 @@ const triggers = {
111113 * @function
112114 * @param {string } [option]
113115 * @param {Object } [optionValue] will be automatically retrieved, if not given
116+ * @param {Event } event the event (input or change) that triggered saving
114117 * @returns {Promise }
115118 * @see {@link saveTrigger }
116119 */
117- export async function runSaveTrigger ( option , optionValue ) {
120+ export async function runSaveTrigger ( option , optionValue , event ) {
118121 if ( option === undefined ) {
119122 console . info ( "run all save triggers" ) ;
120123
@@ -133,32 +136,33 @@ export async function runSaveTrigger(option, optionValue) {
133136 optionValue = await OptionsModel . getOption ( option ) ;
134137 }
135138
136- console . info ( "runSaveTrigger:" , option , optionValue ) ;
139+ console . info ( "runSaveTrigger:" , option , optionValue , event ) ;
137140
138141 // run all registered triggers for that option
139142 const promises = [ ] ;
140143 for ( const trigger of triggers . onSave . filter ( ( trigger ) => trigger . option === option ) ) {
141- promises . push ( trigger . triggerFunc ( optionValue , option ) ) ;
144+ promises . push ( trigger . triggerFunc ( optionValue , option , event ) ) ;
142145 }
143146 return Promise . all ( promises ) ;
144147}
145148
146149/**
147- * Executes special handling for applying certain settings.
148- *
149- * E.g. when a setting is saved, it executes to apply some options live, so the
150- * user immediately sees the change or the change is immediately applied.
151- * If no parameters are passed, this gets and applies all options.
152- *
153- * @protected
154- * @function
155- * @param {string } option
156- * @param {Object } optionValue
157- * @param {Array } saveTriggerValues value returned by potentially run safe triggers
158- * @returns {Promise }
159- * @see {@link overrideSave }
160- */
161- export async function runOverrideSave ( option , optionValue , saveTriggerValues ) {
150+ * Executes special handling for applying certain settings.
151+ *
152+ * E.g. when a setting is saved, it executes to apply some options live, so the
153+ * user immediately sees the change or the change is immediately applied.
154+ * If no parameters are passed, this gets and applies all options.
155+ *
156+ * @protected
157+ * @function
158+ * @param {string } option
159+ * @param {Object } optionValue
160+ * @param {Array } saveTriggerValues value returned by potentially run safe triggers
161+ * @param {Event } event the event (input or change) that triggered saving
162+ * @returns {Promise }
163+ * @see {@link overrideSave }
164+ */
165+ export async function runOverrideSave ( option , optionValue , saveTriggerValues , event ) {
162166 // run all registered triggers for that option
163167 const allRegisteredOverrides = triggers . overrideSave . filter ( ( trigger ) => trigger . option === option ) ;
164168 if ( allRegisteredOverrides . length === 0 ) {
@@ -170,7 +174,8 @@ export async function runOverrideSave(option, optionValue, saveTriggerValues) {
170174 let lastPromise = Promise . resolve ( {
171175 option,
172176 optionValue,
173- saveTriggerValues
177+ saveTriggerValues,
178+ event
174179 } ) ;
175180
176181 for ( const trigger of allRegisteredOverrides ) {
@@ -279,7 +284,7 @@ export async function runOverrideLoad(option, optionValue, elOption, optionValue
279284 * @function
280285 * @param {Event } event
281286 * @returns {void }
282- * @throws {Error }
287+ * @throws {TypeError }
283288 */
284289export function runHtmlEventTrigger ( event ) {
285290 const elOption = event . target ;
@@ -296,7 +301,7 @@ export function runHtmlEventTrigger(event) {
296301 triggerType = "onChange" ;
297302 break ;
298303 default :
299- throw new Error ( "invalid event type attached" ) ;
304+ throw new TypeError ( "invalid event type attached" ) ;
300305 }
301306
302307 // run all registered triggers for that option
0 commit comments