UNPKG

1.92 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const DocumentList_1 = require("./DocumentList");
4const documentTypeListItems_1 = require("./documentTypeListItems");
5// 1:1 with document list builder, but when modifying key parameters (filter, params, child)
6// remove canHandleIntent function since we can't guarantee child editor can handle intent
7class DocumentTypeListBuilder extends DocumentList_1.DocumentListBuilder {
8 constructor(spec) {
9 super();
10 this.spec = spec ? spec : {};
11 }
12 filter(filter) {
13 return this.cloneWithoutDefaultIntentHandler({
14 options: Object.assign({}, (this.spec.options || {}), { filter })
15 });
16 }
17 params(params) {
18 return this.cloneWithoutDefaultIntentHandler({
19 options: Object.assign({}, (this.spec.options || { filter: '' }), { params })
20 });
21 }
22 schemaType(type) {
23 return this.cloneWithoutDefaultIntentHandler({
24 schemaTypeName: typeof type === 'string' ? type : type.name
25 });
26 }
27 child(child) {
28 return this.cloneWithoutDefaultIntentHandler({ child });
29 }
30 clone(withSpec) {
31 const builder = new DocumentTypeListBuilder();
32 builder.spec = Object.assign({}, this.spec, (withSpec || {}));
33 return builder;
34 }
35 cloneWithoutDefaultIntentHandler(withSpec) {
36 const builder = new DocumentTypeListBuilder();
37 const canHandleIntent = this.spec.canHandleIntent;
38 const shouldOverride = canHandleIntent && canHandleIntent.identity === documentTypeListItems_1.DEFAULT_INTENT_HANDLER;
39 const override = shouldOverride ? { canHandleIntent: undefined } : {};
40 builder.spec = Object.assign({}, this.spec, (withSpec || {}), override);
41 return builder;
42 }
43}
44exports.DocumentTypeListBuilder = DocumentTypeListBuilder;
45
46//# sourceMappingURL=DocumentTypeList.js.map