From d762d99c6c4067134edf6587c79b61a2bc291fba Mon Sep 17 00:00:00 2001 From: "Cheng-Chen, Chen" Date: Fri, 27 Nov 2026 23:26:47 +0800 Subject: [PATCH 1/5] Refine request dialogs with a shared responsive form design --- package-lock.json | 4 +- package.json | 2 +- partials/field.hbs | 49 +++--- scripts/ci | 2 +- src/HTMLApi.js | 27 +-- src/i18n.js | 2 + styles/main.scss | 284 +++++++++++++++++++----------- templates/modal.hbs | 2 +- test/product/request-form.test.js | 7 +- 9 files changed, 232 insertions(+), 147 deletions(-) diff --git a/package-lock.json b/package-lock.json index 40c8db2..d28a9b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pasturestack/api-explorer", - "version": "1.1.21", + "version": "1.1.22", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@pasturestack/api-explorer", - "version": "1.1.21", + "version": "1.1.22", "license": "Apache-2.0", "dependencies": { "handlebars": "4.7.10", diff --git a/package.json b/package.json index 66bae0f..97daba6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pasturestack/api-explorer", - "version": "1.1.21", + "version": "1.1.22", "private": true, "description": "Embedded PastureStack explorer for compatible API services", "author": "Original contributors and PastureStack maintainers", diff --git a/partials/field.hbs b/partials/field.hbs index 8486553..73133de 100644 --- a/partials/field.hbs +++ b/partials/field.hbs @@ -1,3 +1,4 @@ +
{{#ifInList type 'array,map'}} {{#each children}}
@@ -18,22 +19,22 @@ {{/if}} {{#ifInList type 'string,date,base64,dnsLabel,dnsLabelRestricted,hostname'}} - + {{/ifInList}} {{#ifEqual type 'json'}} - + {{/ifEqual}} {{#ifInList type 'password,masked'}} - + {{/ifInList}} {{#ifInList type 'number,int,float'}} + {{/ifEqual}} {{#ifEqual type "boolean"}} {{#if field.nullable}} - {{else}} - + {{/if}} {{/ifEqual}} {{#ifEqual type "enum"}} - {{#if field.nullable}} {{/if}} @@ -71,7 +72,7 @@ {{#ifEqual type "reference"}} {{#if field.options}} - {{#if field.nullable}} {{/if}} @@ -84,12 +85,12 @@ {{/ifInMap}} {{else}} - + {{/if}} {{/ifEqual}} {{#ifEqual type "__type__"}} - {{#each field.options}} @@ -101,21 +102,23 @@ {{/if}} -{{#if enlargeable}} - -{{/if}} - -{{#if nullCheck}} -
- -
-{{/if}} +
+ {{#if nullCheck}} +
+ +
+ {{/if}} + {{#if enlargeable}} + + {{/if}} +
{{#unless addingField}} {{#ifInList type 'array,map'}} -
{{/ifInList}} {{/unless}} + +
diff --git a/scripts/ci b/scripts/ci index fe0b2bd..682514d 100644 --- a/scripts/ci +++ b/scripts/ci @@ -35,7 +35,7 @@ for (const section of ['dependencies', 'optionalDependencies']) { } } } -if (pkg.version !== '1.1.21') { +if (pkg.version !== '1.1.22') { fail('PACKAGE_RELEASE_VERSION_UNEXPECTED', `actual=${pkg.version}`); } if (!pkg.engines || pkg.engines.node !== '24.22.3') { diff --git a/src/HTMLApi.js b/src/HTMLApi.js index 5496007..578dc01 100644 --- a/src/HTMLApi.js +++ b/src/HTMLApi.js @@ -540,8 +540,8 @@ HTMLApi.prototype.actionLoad = function(name, obj, body) var html = Handlebars.templates['edit.hbs'](tpl); var popinActions = [ - {id: 'ok', text: 'Show Request', primary: true, onClick: function() { self.showRequest(mode,'POST',actionInput,retry,url); }.bind(self) }, - {id: 'cancel', text: 'Cancel', cancel: true } + {id: 'ok', text: window.PastureStackI18n.text('showRequest'), primary: true, onClick: function() { self.showRequest(mode,'POST',actionInput,retry,url); }.bind(self) }, + {id: 'cancel', text: window.PastureStackI18n.text('cancel'), cancel: true } ]; @@ -973,7 +973,7 @@ HTMLApi.prototype.request = function(method,body,opt,really) if ( really ) { this.setModalActions([ - {id: 'cancel', text: 'Cancel', cancel: true} + {id: 'cancel', text: window.PastureStackI18n.text('cancel'), cancel: true} ]); $('#notsent').hide(); @@ -1045,12 +1045,12 @@ HTMLApi.prototype.request = function(method,body,opt,really) var actions = []; - actions.push({id: 'ok', text: 'Send Request', primary: true, onClick: function() { self.request(method,body,opt,true); } }); + actions.push({id: 'ok', text: window.PastureStackI18n.text('sendRequest'), primary: true, onClick: function() { self.request(method,body,opt,true); } }); if ( this._lastOpt && this._lastOpt.retry ) - actions.push({id: 'edit', text: 'Back to Edit', onClick: this._lastOpt.retry.bind(this,body) }); + actions.push({id: 'edit', text: window.PastureStackI18n.text('backToEdit'), onClick: this._lastOpt.retry.bind(this,body) }); - actions.push({id: 'cancel', text: 'Cancel', cancel: true}); + actions.push({id: 'cancel', text: window.PastureStackI18n.text('cancel'), cancel: true}); self.showModal(html, { destroyOnClose: false, @@ -1123,7 +1123,7 @@ HTMLApi.prototype.requestDone = function(err, body, res) var popinActions = [ {id: 'reload', text: 'Reload', onClick: this.reload.bind(this)}, {id: 'up', text: 'Go Up', onClick: function() { this.up(); }.bind(this) }, - {id: 'cancel', text: 'Close', cancel: true} + {id: 'cancel', text: window.PastureStackI18n.text('close'), cancel: true} ]; if ( loc ) @@ -1324,12 +1324,12 @@ HTMLApi.prototype.showEdit = function(data,update,schema,url) self.showEdit(body||self._lastRequestBody||data, update, schema, url); } - var title = (update ? 'Edit' : 'Create') +' '+ schema.id; + var title = window.PastureStackI18n.text(update ? 'edit' : 'create') +' '+ schema.id; var html = Handlebars.templates['edit.hbs'](tpl); var method = (update ? 'PUT' : 'POST'); var popinActions = [ - {id: 'ok', text: 'Show Request', primary: true, onClick: function() { self.showRequest(mode, method,schema,retry,url); }.bind(self) }, - {id: 'cancel', text: 'Cancel', cancel: true } + {id: 'ok', text: window.PastureStackI18n.text('showRequest'), primary: true, onClick: function() { self.showRequest(mode, method,schema,retry,url); }.bind(self) }, + {id: 'cancel', text: window.PastureStackI18n.text('cancel'), cancel: true } ]; self.showModal(html, { @@ -1857,15 +1857,16 @@ HTMLApi.prototype.toggleNull = function(check) HTMLApi.prototype.switchToTextarea = function(button) { var $button = $(button); - var $par = $($button.parent()); - var $input = $('INPUT[type="text"]', $par); + var $par = $button.closest('.field-editor'); + if ( !$par.length ) $par = $button.parent(); + var $input = $('INPUT[type="text"]:not(.key)', $par).first(); if ( !$input[0] ) return; var val = $input.val(); - var $textarea = $('