cotomy 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -3
- package/dist/browser/cotomy.js +29 -2
- package/dist/browser/cotomy.js.map +1 -1
- package/dist/browser/cotomy.min.js +1 -1
- package/dist/browser/cotomy.min.js.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/api.js +21 -1
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/form.js +2 -2
- package/dist/esm/form.js.map +1 -1
- package/dist/esm/page.js +7 -0
- package/dist/esm/page.js.map +1 -1
- package/dist/types/api.d.ts +4 -1
- package/dist/types/page.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -243,7 +243,7 @@ The Form layer builds on `CotomyElement` for common form flows.
|
|
|
243
243
|
- `loadActionUrl: string` — Defaults to `actionUrl`; override or set for custom endpoints
|
|
244
244
|
- `canLoad: boolean` — Defaults to `hasEntityKey`
|
|
245
245
|
- Naming & binding
|
|
246
|
-
- `bindNameGenerator(): ICotomyBindNameGenerator` — Defaults to `
|
|
246
|
+
- `bindNameGenerator(): ICotomyBindNameGenerator` — Defaults to `CotomyViewRenderer.defaultBindNameGenerator` (initial value: `CotomyBracketBindNameGenerator`, `user[name]`)
|
|
247
247
|
- `renderer(): CotomyViewRenderer` — Applies `[data-cotomy-bind]` to view elements
|
|
248
248
|
- `filler(type, (input, value))` — Register fillers; defaults provided for `datetime-local`, `checkbox`, `radio`
|
|
249
249
|
- Fills non-array, non-object fields by matching input/select/textarea `name`
|
|
@@ -262,8 +262,7 @@ Example:
|
|
|
262
262
|
|
|
263
263
|
```ts
|
|
264
264
|
const view = new CotomyViewRenderer(
|
|
265
|
-
new CotomyElement(document.querySelector("#profile")!)
|
|
266
|
-
new CotomyBracketBindNameGenerator()
|
|
265
|
+
new CotomyElement(document.querySelector("#profile")!)
|
|
267
266
|
);
|
|
268
267
|
|
|
269
268
|
await view.applyAsync(apiResponse); // apiResponse is CotomyApiResponse from CotomyApi
|
|
@@ -289,6 +288,24 @@ form.apiFailed(e => console.error("API failed", e.response.status));
|
|
|
289
288
|
form.submitFailed(e => console.warn("Submit failed", e.response.status));
|
|
290
289
|
```
|
|
291
290
|
|
|
291
|
+
To switch the default bind naming style for a page, set it from your page controller:
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
import {
|
|
295
|
+
CotomyDotBindNameGenerator,
|
|
296
|
+
CotomyEntityFillApiForm,
|
|
297
|
+
CotomyPageController
|
|
298
|
+
} from "cotomy";
|
|
299
|
+
|
|
300
|
+
CotomyPageController.set(class extends CotomyPageController {
|
|
301
|
+
protected override async initializeAsync(): Promise<void> {
|
|
302
|
+
this.defaultBindNameGenerator = new CotomyDotBindNameGenerator();
|
|
303
|
+
|
|
304
|
+
this.setForm(CotomyEntityFillApiForm.byId("profile-form", CotomyEntityFillApiForm)!);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
292
309
|
### Entity API forms
|
|
293
310
|
|
|
294
311
|
`CotomyEntityApiForm` targets REST endpoints that identify records with a single surrogate key.
|
package/dist/browser/cotomy.js
CHANGED
|
@@ -2451,8 +2451,28 @@ class CotomyDotBindNameGenerator {
|
|
|
2451
2451
|
return parent ? `${parent}[${index}]` : `[${index}]`;
|
|
2452
2452
|
}
|
|
2453
2453
|
}
|
|
2454
|
+
class CotomyBindNameGeneratorProvider {
|
|
2455
|
+
static getDefault() {
|
|
2456
|
+
return this._default ?? (this._default = new CotomyBracketBindNameGenerator());
|
|
2457
|
+
}
|
|
2458
|
+
static setDefault(generator) {
|
|
2459
|
+
this._default = generator;
|
|
2460
|
+
}
|
|
2461
|
+
static resetDefault() {
|
|
2462
|
+
this._default = undefined;
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2454
2465
|
class CotomyViewRenderer {
|
|
2455
|
-
|
|
2466
|
+
static get defaultBindNameGenerator() {
|
|
2467
|
+
return CotomyBindNameGeneratorProvider.getDefault();
|
|
2468
|
+
}
|
|
2469
|
+
static set defaultBindNameGenerator(generator) {
|
|
2470
|
+
CotomyBindNameGeneratorProvider.setDefault(generator);
|
|
2471
|
+
}
|
|
2472
|
+
static resetDefaultBindNameGenerator() {
|
|
2473
|
+
CotomyBindNameGeneratorProvider.resetDefault();
|
|
2474
|
+
}
|
|
2475
|
+
constructor(element, bindNameGenerator = CotomyViewRenderer.defaultBindNameGenerator) {
|
|
2456
2476
|
this.element = element;
|
|
2457
2477
|
this.bindNameGenerator = bindNameGenerator;
|
|
2458
2478
|
this._renderers = {};
|
|
@@ -3048,7 +3068,7 @@ class CotomyEntityFillApiForm extends CotomyEntityApiForm {
|
|
|
3048
3068
|
return this.actionUrl;
|
|
3049
3069
|
}
|
|
3050
3070
|
bindNameGenerator() {
|
|
3051
|
-
return
|
|
3071
|
+
return CotomyViewRenderer.defaultBindNameGenerator;
|
|
3052
3072
|
}
|
|
3053
3073
|
renderer() {
|
|
3054
3074
|
return new CotomyViewRenderer(this, this.bindNameGenerator());
|
|
@@ -3152,6 +3172,7 @@ var utc_default = /*#__PURE__*/__webpack_require__.n(utc);
|
|
|
3152
3172
|
|
|
3153
3173
|
|
|
3154
3174
|
|
|
3175
|
+
|
|
3155
3176
|
dayjs_min_default().extend((utc_default()));
|
|
3156
3177
|
dayjs_min_default().extend((timezone_default()));
|
|
3157
3178
|
class CotomyUrl {
|
|
@@ -3213,6 +3234,12 @@ class CotomyPageController {
|
|
|
3213
3234
|
}
|
|
3214
3235
|
return this._instance;
|
|
3215
3236
|
}
|
|
3237
|
+
get defaultBindNameGenerator() {
|
|
3238
|
+
return CotomyViewRenderer.defaultBindNameGenerator;
|
|
3239
|
+
}
|
|
3240
|
+
set defaultBindNameGenerator(value) {
|
|
3241
|
+
CotomyViewRenderer.defaultBindNameGenerator = value;
|
|
3242
|
+
}
|
|
3216
3243
|
setForm(form) {
|
|
3217
3244
|
if (!form.id) {
|
|
3218
3245
|
form.generateId();
|