<commit_before>define('JSComposer/Instance/ObjectInstance', ['JSComposer/Utils', 'JSComposer/Instance', 'JSComposer/Entry'], function(Utils, Instance, Entry) {
    // TODO: Update for schema changes, including changes to
    // additionalProperties and properties.
    //
    // Optional properties are now defined as any defined
    // under "properties" but not listed in "required",
    // additionalProperties is now defined as either a
    // boolean (in which case any valid type shall suffice)
    // or a single schema (to which any additionalProperties
    // must conform).
    function ObjectInstance(context, parent, schema, value) {
        Instance.apply(this, arguments);
        // We need all these schema properties
        this.properties             = Utils.ldef(this.properties, {});
        this.additionalProperties   = Utils.ldef(this.additionalProperties, true);
        this.patternProperties      = Utils.ldef(this.patternProperties, {});
        this.required               = Utils.ldef(this.required, []);

        // Some internal properties
        this.supported              = Utils.getKeys(this.properties);
        this.patterns               = Utils.map(function(rxs) { return new RegExp(rxs); }, Utils.getKeys(this.patternProperties));
        this.property_map           = {
            'required':                 [],
            'optional':                 [],
            'pattern':                  [],
            'additional':               []
        };
        this.property_pam           = {};
        this.entries                = {
            'required':                 [],
            'optional':                 [],
            'pattern':                  [],
            'additional':               [],
            'by_key':                   {}
        };
        this.elements.sections      = {};
        this.section_count          = 0;
        this.title                  = Utils.ldef(this.title, "An Object");

        // Figure out what our current value defines and what category they fall into
        value = Utils.ldef(value, {});

        this.property_map.required = this.required;
        for (var i = 0; i < this.property_map.required.length; ++i) {
            this.property_pam[this.property_map.required[i]] = 'required';
        }

        for (var k in this.properties) {
            if (this.property_pam.hasOwnProperty(k)) continue;
            this.property_map.optional.push(k);
            this.property_pam[k] = 'optional';
        }

        for (var k in value) {
            if (this.property_pam.hasOwnProperty(k)) continue;
            if (Utils.any(function(rx) { return e.exec(k) !== null; }, this.patterns)) {
                this.property_map.pattern.push(k);
                this.property_pam[k] = 'pattern';
            } else {
                this.property_map.additional.push(k);
                this.property_pam[k] = 'additional';
            }
        }

        // UI Components
        this.elements.body      = Utils.makeElement('div', {'className':'panel-body'});
        this.elements.header    = Utils.makeElement('div', {'className':'panel-heading'});
        this.elements.title     = Utils.makeElement('h3', {'className':'panel-title'});
        Utils.setText(this.elements.title, this.title);
        Utils.applyClass(this.elements.ctr, 'object');
        this.elements.header.appendChild(this.elements.title);
        this.elements.ctr.appendChild(this.elements.header);
        this.elements.ctr.appendChild(this.elements.body);

        // Rendering
        value = Utils.ldef(value, {});

        if (this.property_map.required.length > 0) {
            this.AddSection('required', this.property_map.required, value);
        }

        if (this.property_map.optional.length > 0) {
            this.AddSection('optional', this.property_map.optional, value);
        }

        if (this.patterns.length > 0) {
            this.AddSection('pattern', this.property_map.pattern, value);
        }

        console.log("Additional properties, eh? ", this.additionalProperties);
        if (this.additionalProperties !== false) {
            this.AddSection('additional', this.property_map.additional, value);
        }

        this.CompilePatterns();
    }

    ObjectInstance.prototype = new Instance();
    ObjectInstance.prototype.constructor = ObjectInstance;

    ObjectInstance.Default      = {};
    ObjectInstance.Descriptor   = {
        'type':         'object_type', // Insert maniacal laughter here
        'properties':   {
            'label':        {'type':'text', 'label':'Label'},
            'header':       {'type':'boolean', 'label':'Display Header'},
            'properties':   {
                'type':                     'object',
                'additionalProperties':     {},
                'label':                    'Properties'
            },
            'order':        {'type':'order','options':[],'label':'Instance Order'}
        }
    };
    ObjectInstance.PropertyOptions      = {
        'required':                 {'deletable':false, 'more':false, 'header':'Required Properties'},
        'optional':                 {'deletable':true, 'more':true, 'header':'Optional Properties'},
        'pattern':                  {'deletable':true, 'more':true, 'header':'Patterned Properties'},
        'additional':               {'deletable':true, 'more':true, 'header':'Extra Properties'}
    };

    ObjectInstance.prototype.GetKeySchema = function(type) {
        switch (type) {
            case 'required':
                return Schema.Ref('#/definitions/label');
                break;
            case 'optional':
                return {'enum':this.property_map.optional};
                break;
            case 'pattern':
            default:
                return {'type':'string'};
        }
    };

    ObjectInstance.prototype.AddSection = function(type, properties, value) {
        var options = ObjectInstance.PropertyOptions[type];
        ++this.section_count;

        if (type == 'required') {
            console.log("We're the first!");
            var ctr     = this.elements.ctr,
                header  = this.elements.header,
                title   = this.elements.title,
                body    = this.elements.body,
                footer  = undefined,
                more    = undefined;
            if (options.more) {
                footer  = Utils.makeElement('div', {'className':'object-section panel-footer text-right'});
                ctr.appendChild(footer);
            }
            Utils.applyClass(title, 'float-pair');
            header.style.overflow = 'auto';
        } else {
            var ctr     = Utils.makeElement('div', {'className':'object-section panel panel-default'}),
                header  = Utils.makeElement('div', {'className':'object-section panel-heading'}),
                title   = Utils.makeElement('h4', {'className':'object-section panel-title'}),
                body    = Utils.makeElement('div', {'className':'object-section panel-body'}),
                footer  = Utils.makeElement('div', {'className':'object-section panel-footer text-right'}),
                more    = undefined;

            Utils.applyClass(body, type);
            Utils.applyClass(header, type);
            Utils.setText(title, options.header);
            header.appendChild(title);
            ctr.appendChild(header);
            ctr.appendChild(body);
            ctr.appendChild(footer);
            this.elements.body.appendChild(ctr);
        }


        if (options.more) {
            var $self = this;
            more = Utils.makeElement('button', {'type':'button', 'className':'create btn btn-success'});
            Utils.setText(more, 'Add');
            Utils.attachEvent(more, 'click', function() {
                $self.OnAddEntry(type);
            });
            footer.appendChild(more);
        }

        this.elements.sections[type] = body;

        for (var k in properties) {
            if (type !== 'properties' && !value.hasOwnProperty(k)) continue;
            var s = this.GetKeySchema(type);
            s.title = typeof properties[k].title != 'undefined' ? properties[k].title : s.title;
            this.AddEntry(type, s, properties[k], k, value[k], ObjectInstance.PropertyOptions[type]);
        }
    }

    ObjectInstance.prototype.AddEntry = function(type, key_desc, value_desc, key, value) {
        var $self       = this,
            entry       = new Entry(this.context, this, key_desc, value_desc, key, value),
            val_field   = entry.GetValueInstance(),<commit_msg>Fixes for object instance! (required fields plz)<commit_after>define('JSComposer/Instance/ObjectInstance', ['JSComposer/Utils', 'JSComposer/Schema', 'JSComposer/Instance', 'JSComposer/Entry'], function(Utils, Schema, Instance, Entry) {
    // TODO: Update for schema changes, including changes to
    // additionalProperties and properties.
    //
    // Optional properties are now defined as any defined
    // under "properties" but not listed in "required",
    // additionalProperties is now defined as either a
    // boolean (in which case any valid type shall suffice)
    // or a single schema (to which any additionalProperties
    // must conform).
    function ObjectInstance(context, parent, schema, value) {
        Instance.apply(this, arguments);
        // We need all these schema properties
        this.properties             = Utils.ldef(this.properties, {});
        this.additionalProperties   = Utils.ldef(this.additionalProperties, true);
        this.patternProperties      = Utils.ldef(this.patternProperties, {});
        this.required               = Utils.ldef(this.required, []);

        // Some internal properties
        this.supported              = Utils.getKeys(this.properties);
        this.patterns               = Utils.map(function(rxs) { return new RegExp(rxs); }, Utils.getKeys(this.patternProperties));
        this.property_map           = {
            'required':                 [],
            'optional':                 [],
            'pattern':                  [],
            'additional':               []
        };
        this.property_pam           = {};
        this.entries                = {
            'required':                 [],
            'optional':                 [],
            'pattern':                  [],
            'additional':               [],
            'by_key':                   {}
        };
        this.elements.sections      = {};
        this.section_count          = 0;
        this.title                  = Utils.ldef(this.title, "An Object");

        // Figure out what our current value defines and what category they fall into
        value = Utils.ldef(value, {});

        this.property_map.required = this.required;
        for (var i = 0; i < this.property_map.required.length; ++i) {
            this.property_pam[this.property_map.required[i]] = 'required';
        }

        for (var k in this.properties) {
            if (this.property_pam.hasOwnProperty(k)) continue;
            this.property_map.optional.push(k);
            this.property_pam[k] = 'optional';
        }

        for (var k in value) {
            if (this.property_pam.hasOwnProperty(k)) continue;
            if (Utils.any(function(rx) { return e.exec(k) !== null; }, this.patterns)) {
                this.property_map.pattern.push(k);
                this.property_pam[k] = 'pattern';
            } else {
                this.property_map.additional.push(k);
                this.property_pam[k] = 'additional';
            }
        }

        // UI Components
        this.elements.body      = Utils.makeElement('div', {'className':'panel-body'});
        this.elements.header    = Utils.makeElement('div', {'className':'panel-heading'});
        this.elements.title     = Utils.makeElement('h3', {'className':'panel-title'});
        Utils.setText(this.elements.title, this.title);
        Utils.applyClass(this.elements.ctr, 'object');
        this.elements.header.appendChild(this.elements.title);
        this.elements.ctr.appendChild(this.elements.header);
        this.elements.ctr.appendChild(this.elements.body);

        // Rendering
        value = Utils.ldef(value, {});

        if (this.property_map.required.length > 0) {
            console.log("Adding section for required properties: ", this.property_map.required);
            this.AddSection('required', this.property_map.required, value);
        }

        if (this.property_map.optional.length > 0) {
            this.AddSection('optional', this.property_map.optional, value);
        }

        if (this.patterns.length > 0) {
            this.AddSection('pattern', this.property_map.pattern, value);
        }

        console.log("Additional properties, eh? ", this.additionalProperties);
        if (this.additionalProperties !== false) {
            this.AddSection('additional', this.property_map.additional, value);
        }

        this.CompilePatterns();
    }

    ObjectInstance.prototype = new Instance();
    ObjectInstance.prototype.constructor = ObjectInstance;

    ObjectInstance.Default      = {};
    ObjectInstance.Descriptor   = {
        'type':         'object_type', // Insert maniacal laughter here
        'properties':   {
            'label':        {'type':'text', 'label':'Label'},
            'header':       {'type':'boolean', 'label':'Display Header'},
            'properties':   {
                'type':                     'object',
                'additionalProperties':     {},
                'label':                    'Properties'
            },
            'order':        {'type':'order','options':[],'label':'Instance Order'}
        }
    };
    ObjectInstance.PropertyOptions      = {
        'required':                 {'deletable':false, 'more':false, 'header':'Required Properties'},
        'optional':                 {'deletable':true, 'more':true, 'header':'Optional Properties'},
        'pattern':                  {'deletable':true, 'more':true, 'header':'Patterned Properties'},
        'additional':               {'deletable':true, 'more':true, 'header':'Extra Properties'}
    };

    ObjectInstance.prototype.GetKeySchema = function(type) {
        switch (type) {
            case 'required':
                return Schema.Ref('#/definitions/label');
                break;
            case 'optional':
                return {'enum':this.property_map.optional};
                break;
            case 'pattern':
            default:
                return {'type':'string'};
        }
    };

    ObjectInstance.prototype.AddSection = function(type, properties, value) {
        var options = ObjectInstance.PropertyOptions[type];
        ++this.section_count;

        if (type == 'required') {
            console.log("We're the first!");
            var ctr     = this.elements.ctr,
                header  = this.elements.header,
                title   = this.elements.title,
                body    = this.elements.body,
                footer  = undefined,
                more    = undefined;
            if (options.more) {
                footer  = Utils.makeElement('div', {'className':'object-section panel-footer text-right'});
                ctr.appendChild(footer);
            }
            Utils.applyClass(title, 'float-pair');
            header.style.overflow = 'auto';
        } else {
            var ctr     = Utils.makeElement('div', {'className':'object-section panel panel-default'}),
                header  = Utils.makeElement('div', {'className':'object-section panel-heading'}),
                title   = Utils.makeElement('h4', {'className':'object-section panel-title'}),
                body    = Utils.makeElement('div', {'className':'object-section panel-body'}),
                footer  = Utils.makeElement('div', {'className':'object-section panel-footer text-right'}),
                more    = undefined;

            Utils.applyClass(body, type);
            Utils.applyClass(header, type);
            Utils.setText(title, options.header);
            header.appendChild(title);
            ctr.appendChild(header);
            ctr.appendChild(body);
            ctr.appendChild(footer);
            this.elements.body.appendChild(ctr);
        }


        if (options.more) {
            var $self = this;
            more = Utils.makeElement('button', {'type':'button', 'className':'create btn btn-success'});
            Utils.setText(more, 'Add');
            Utils.attachEvent(more, 'click', function() {
                $self.OnAddEntry(type);
            });
            footer.appendChild(more);
        }

        this.elements.sections[type] = body;

        for (var i = 0; i < properties.length; ++i) {
            var k = properties[i];
            console.log("Adding entry for ", properties[k], "; value: ", value[k]);
            if (type !== 'required' && !value.hasOwnProperty(k)) continue;
            var s = this.GetKeySchema(type);
            s.title = typeof this.properties[k].title != 'undefined' ? this.properties[k].title : s.title;
            this.AddEntry(type, s, this.properties[k], k, value[k], ObjectInstance.PropertyOptions[type]);
        }
    }

    ObjectInstance.prototype.AddEntry = function(type, key_desc, value_desc, key, value) {
        var $self       = this,
            entry       = new Entry(this.context, this, key_desc, value_desc, key, value),
            val_field   = entry.GetValueInstance(),
{'fraction_non_alphanumeric': 0.1338008095319537, 'fraction_numerical': 0.0008551393877201984, 'mean_word_length': 1.8551432291666667, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1677648', 'n_tokens_mistral': 4661, 'n_tokens_neox': 4466, 'n_words': 882}