<commit_before>(function () {
    "use strict";


    /**
     * @ngdoc directive
     * @name umbraco.directives.directive:umbBlockListPropertyEditor
     * @function
     *
     * @description
     * The component for the block list property editor.
     */
    angular
        .module("umbraco")
        .component("umbBlockListPropertyEditor", {
            templateUrl: "views/propertyeditors/blocklist/umb-block-list-property-editor.html",
            controller: BlockListController,
            controllerAs: "vm",
            bindings: {
                model: "=",
                propertyForm: "="
            },
            require: {
                umbProperty: "?^umbProperty",
                umbVariantContent: '?^^umbVariantContent',
                umbVariantContentEditors: '?^^umbVariantContentEditors',
                umbElementEditorContent: '?^^umbElementEditorContent'
            }
        });

    function BlockListController($scope, editorService, clipboardService, localizationService, overlayService, blockEditorService) {
        
        var unsubscribe = [];
        var modelObject;

        // Property actions:
        var copyAllBlocksAction;
        var deleteAllBlocksAction;

        var inlineEditing = false;
        var liveEditing = true;

        var vm = this;

        vm.loading = true;
        vm.currentBlockInFocus = null;
        vm.setBlockFocus = function(block) {
            if(vm.currentBlockInFocus !== null) {
                vm.currentBlockInFocus.focus = false;
            }
            vm.currentBlockInFocus = block;
            block.focus = true;
        }
        vm.supportCopy = clipboardService.isSupported();

        vm.layout = [];// The layout object specific to this Block Editor, will be a direct reference from Property Model.
        vm.availableBlockTypes = [];// Available block entries of this property editor.

        var labels = {};
        vm.labels = labels;
        localizationService.localizeMany(["grid_addElement", "content_createEmpty"]).then(function (data) {
            labels.grid_addElement = data[0];
            labels.content_createEmpty = data[1];
        });





        vm.$onInit = function() {

            inlineEditing = vm.model.config.useInlineEditingAsDefault;
            liveEditing = vm.model.config.useLiveEditing;

            vm.validationLimit = vm.model.config.validationLimit;

            vm.listWrapperStyles = {};
            
            if (vm.model.config.maxPropertyWidth) {
                vm.listWrapperStyles['max-width'] = vm.model.config.maxPropertyWidth;
            }

            // We need to ensure that the property model value is an object, this is needed for modelObject to recive a reference and keep that updated.
            if(typeof vm.model.value !== 'object' || vm.model.value === null) {// testing if we have null or undefined value or if the value is set to another type than Object.
                vm.model.value = {};
            }

            var scopeOfExistence = $scope;
            if(vm.umbVariantContentEditors && vm.umbVariantContentEditors.getScope) {
                scopeOfExistence = vm.umbVariantContentEditors.getScope();
            }
            
            // Create Model Object, to manage our data for this Block Editor.
            modelObject = blockEditorService.createModelObject(vm.model.value, vm.model.editor, vm.model.config.blocks, scopeOfExistence, $scope);
            modelObject.load().then(onLoaded);

            copyAllBlocksAction = {
                labelKey: "clipboard_labelForCopyAllEntries",
                labelTokens: [vm.model.label],
                icon: "documents",
                method: requestCopyAllBlocks,
                isDisabled: true
            }
            deleteAllBlocksAction = {
                labelKey: 'clipboard_labelForRemoveAllEntries',
                labelTokens: [],
                icon: 'trash',
                method: requestDeleteAllBlocks,
                isDisabled: true
            }

            var propertyActions = [
                copyAllBlocksAction,
                deleteAllBlocksAction
            ];
            
            if (vm.umbProperty) {
                vm.umbProperty.setPropertyActions(propertyActions);
            }
        };

        

        
        function setDirty() {
            if (vm.propertyForm) {
                vm.propertyForm.$setDirty();
            }
        }
        
        function onLoaded() {

            // Store a reference to the layout model, because we need to maintain this model.
            vm.layout = modelObject.getLayout([]);

            // Append the blockObjects to our layout.
            vm.layout.forEach(entry => {
                if (entry.$block === undefined || entry.$block === null) {
                    var block = getBlockObject(entry);
    
                    // If this entry was not supported by our property-editor it would return 'null'.
                    if(block !== null) {
                        entry.$block = block;
                    }
                }
            });

            vm.availableContentTypesAliases = modelObject.getAvailableAliasesForBlockContent();
            vm.availableBlockTypes = modelObject.getAvailableBlocksForBlockPicker();

            vm.loading = false;

            $scope.$evalAsync();

        }

        function getDefaultViewForBlock(block) {
            
            if (block.config.unsupported === true)
                return "views/propertyeditors/blocklist/blocklistentryeditors/unsupportedblock/unsupportedblock.editor.html";

            if (inlineEditing === true)
                return "views/propertyeditors/blocklist/blocklistentryeditors/inlineblock/inlineblock.editor.html";
            return "views/propertyeditors/blocklist/blocklistentryeditors/labelblock/labelblock.editor.html";
        }

        function getBlockObject(entry) {<commit_msg>check for $block.data, to verify that the blockObject is not in a destroyed state.<commit_after>(function () {
    "use strict";


    /**
     * @ngdoc directive
     * @name umbraco.directives.directive:umbBlockListPropertyEditor
     * @function
     *
     * @description
     * The component for the block list property editor.
     */
    angular
        .module("umbraco")
        .component("umbBlockListPropertyEditor", {
            templateUrl: "views/propertyeditors/blocklist/umb-block-list-property-editor.html",
            controller: BlockListController,
            controllerAs: "vm",
            bindings: {
                model: "=",
                propertyForm: "="
            },
            require: {
                umbProperty: "?^umbProperty",
                umbVariantContent: '?^^umbVariantContent',
                umbVariantContentEditors: '?^^umbVariantContentEditors',
                umbElementEditorContent: '?^^umbElementEditorContent'
            }
        });

    function BlockListController($scope, editorService, clipboardService, localizationService, overlayService, blockEditorService) {
        
        var unsubscribe = [];
        var modelObject;

        // Property actions:
        var copyAllBlocksAction;
        var deleteAllBlocksAction;

        var inlineEditing = false;
        var liveEditing = true;

        var vm = this;

        vm.loading = true;
        vm.currentBlockInFocus = null;
        vm.setBlockFocus = function(block) {
            if(vm.currentBlockInFocus !== null) {
                vm.currentBlockInFocus.focus = false;
            }
            vm.currentBlockInFocus = block;
            block.focus = true;
        }
        vm.supportCopy = clipboardService.isSupported();

        vm.layout = [];// The layout object specific to this Block Editor, will be a direct reference from Property Model.
        vm.availableBlockTypes = [];// Available block entries of this property editor.

        var labels = {};
        vm.labels = labels;
        localizationService.localizeMany(["grid_addElement", "content_createEmpty"]).then(function (data) {
            labels.grid_addElement = data[0];
            labels.content_createEmpty = data[1];
        });





        vm.$onInit = function() {

            inlineEditing = vm.model.config.useInlineEditingAsDefault;
            liveEditing = vm.model.config.useLiveEditing;

            vm.validationLimit = vm.model.config.validationLimit;

            vm.listWrapperStyles = {};
            
            if (vm.model.config.maxPropertyWidth) {
                vm.listWrapperStyles['max-width'] = vm.model.config.maxPropertyWidth;
            }

            // We need to ensure that the property model value is an object, this is needed for modelObject to recive a reference and keep that updated.
            if(typeof vm.model.value !== 'object' || vm.model.value === null) {// testing if we have null or undefined value or if the value is set to another type than Object.
                vm.model.value = {};
            }

            var scopeOfExistence = $scope;
            if(vm.umbVariantContentEditors && vm.umbVariantContentEditors.getScope) {
                scopeOfExistence = vm.umbVariantContentEditors.getScope();
            }
            
            // Create Model Object, to manage our data for this Block Editor.
            modelObject = blockEditorService.createModelObject(vm.model.value, vm.model.editor, vm.model.config.blocks, scopeOfExistence, $scope);
            modelObject.load().then(onLoaded);

            copyAllBlocksAction = {
                labelKey: "clipboard_labelForCopyAllEntries",
                labelTokens: [vm.model.label],
                icon: "documents",
                method: requestCopyAllBlocks,
                isDisabled: true
            }
            deleteAllBlocksAction = {
                labelKey: 'clipboard_labelForRemoveAllEntries',
                labelTokens: [],
                icon: 'trash',
                method: requestDeleteAllBlocks,
                isDisabled: true
            }

            var propertyActions = [
                copyAllBlocksAction,
                deleteAllBlocksAction
            ];
            
            if (vm.umbProperty) {
                vm.umbProperty.setPropertyActions(propertyActions);
            }
        };

        

        
        function setDirty() {
            if (vm.propertyForm) {
                vm.propertyForm.$setDirty();
            }
        }
        
        function onLoaded() {

            // Store a reference to the layout model, because we need to maintain this model.
            vm.layout = modelObject.getLayout([]);

            // Append the blockObjects to our layout.
            vm.layout.forEach(entry => {
                // $block must have the data property to be a valid BlockObject, if not its concidered as a destroyed blockObject.
                if (entry.$block === undefined || entry.$block === null || entry.$block.data === undefined) {
                    var block = getBlockObject(entry);
    
                    // If this entry was not supported by our property-editor it would return 'null'.
                    if(block !== null) {
                        entry.$block = block;
                    }
                }
            });

            vm.availableContentTypesAliases = modelObject.getAvailableAliasesForBlockContent();
            vm.availableBlockTypes = modelObject.getAvailableBlocksForBlockPicker();

            vm.loading = false;

            $scope.$evalAsync();

        }

        function getDefaultViewForBlock(block) {
            
            if (block.config.unsupported === true)
                return "views/propertyeditors/blocklist/blocklistentryeditors/unsupportedblock/unsupportedblock.editor.html";

            if (inlineEditing === true)
                return "views/propertyeditors/blocklist/blocklistentryeditors/inlineblock/inlineblock.editor.html";
            return "views/propertyeditors/blocklist/blocklistentryeditors/labelblock/labelblock.editor.html";
        }

        function getBlockObject(entry) {
{'fraction_non_alphanumeric': 0.0910742300388077, 'fraction_numerical': 0.0003302782594335728, 'mean_word_length': 1.7824488858258671, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7493176', 'n_tokens_mistral': 3025, 'n_tokens_neox': 2890, 'n_words': 654}