Skip to content

Commit

Permalink
reverts
Browse files Browse the repository at this point in the history
  • Loading branch information
tongsonbarbs committed Mar 5, 2025
1 parent da68c8d commit 74c0320
Show file tree
Hide file tree
Showing 14 changed files with 362 additions and 383 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/* eslint-disable no-undef */
export const discover = jest.fn(() => ({}));
75 changes: 37 additions & 38 deletions packages/devextreme-vue/src/core/children-processing.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
/* eslint-disable import/named */
import { PatchFlags } from '@vue/shared';
import { VNode } from 'vue';
import Configuration from './configuration';
import { IConfigurable, IConfigurationComponent } from './configuration-component';
import { configurationChildren, getComponentInfo, getNormalizedProps } from './vue-helper';

function pullAllChildren(directChildren: VNode[], allChildren: VNode[], config: Configuration): void {
if(!directChildren || directChildren.length === 0) { return; }
if (!directChildren || directChildren.length === 0) { return; }

pullConfigComponents(directChildren, allChildren, config);
pullConfigComponents(directChildren, allChildren, config);
}

export function isFragment(node: any): boolean {
const { patchFlag } = node;
return patchFlag === PatchFlags.KEYED_FRAGMENT
const { patchFlag } = node;
return patchFlag === PatchFlags.KEYED_FRAGMENT
|| patchFlag === PatchFlags.UNKEYED_FRAGMENT
|| patchFlag === PatchFlags.STABLE_FRAGMENT
|| patchFlag === PatchFlags.BAIL;
}

export function pullConfigComponents(children: VNode[], nodes: VNode[], ownerConfig: Configuration): void {
children.forEach((node) => {
if(isFragment(node) && Array.isArray(node.children)) {
pullConfigComponents(node.children as any as VNode[], nodes, ownerConfig);
}
if(!isFragment(node)) {
nodes.push(node);
}
if(!node) { return; }

const componentInfo = getComponentInfo(node) as any as IConfigurationComponent;
if(!componentInfo || !componentInfo.$_optionName) { return; }

const componentChildren = configurationChildren(node);
const initialValues = {
...componentInfo.$_predefinedProps,
...getNormalizedProps(node.props || {}),
};

const config = ownerConfig.createNested(
componentInfo.$_optionName,
initialValues,
componentInfo.$_isCollectionItem,
componentInfo.$_expectedChildren,
);

(node as any as IConfigurable).$_config = config;
(node as any as IConfigurable).$_innerChanges = {};

if(componentChildren) {
pullConfigComponents(componentChildren, nodes, config);
}
});
children.forEach((node) => {
if (isFragment(node) && Array.isArray(node.children)) {
pullConfigComponents(node.children as any as VNode[], nodes, ownerConfig);
}
if (!isFragment(node)) {
nodes.push(node);
}
if (!node) { return; }

const componentInfo = getComponentInfo(node) as any as IConfigurationComponent;
if (!componentInfo || !componentInfo.$_optionName) { return; }

const componentChildren = configurationChildren(node);
const initialValues = {
...componentInfo.$_predefinedProps,
...getNormalizedProps(node.props || {}),
};

const config = ownerConfig.createNested(
componentInfo.$_optionName,
initialValues,
componentInfo.$_isCollectionItem,
componentInfo.$_expectedChildren,
);

(node as any as IConfigurable).$_config = config;
(node as any as IConfigurable).$_innerChanges = {};

if (componentChildren) {
pullConfigComponents(componentChildren, nodes, config);
}
});
}

export {
pullAllChildren,
pullAllChildren,
};
4 changes: 0 additions & 4 deletions packages/devextreme-vue/src/core/component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* eslint-disable no-prototype-builtins */
/* eslint-disable spellcheck/spell-checker */
/* eslint-disable no-restricted-syntax */
/* eslint-disable import/named */
import {
ComponentPublicInstance, defineComponent, h, VNode,
} from 'vue';
Expand Down
6 changes: 3 additions & 3 deletions packages/devextreme-vue/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ interface IOptions {
}

let config: IOptions = {
deepWatch: false,
deepWatch: false,
};

function setOptions(options: Partial<IOptions>): void {
config = { ...config, ...options };
config = { ...config, ...options };
}

function getOption<TName extends keyof IOptions>(optionName: TName): IOptions[TName] {
return config[optionName];
return config[optionName];
}

export default setOptions;
Expand Down
131 changes: 65 additions & 66 deletions packages/devextreme-vue/src/core/configuration-component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/named
import { ComponentPublicInstance, defineComponent } from 'vue';
import { getNodeOptions, getNodeTypeOfComponent } from './vue-helper';

Expand Down Expand Up @@ -26,87 +25,87 @@ interface IComponentInfo {
}

function getConfig(vueInstance: Pick<ComponentPublicInstance, '$'>): Configuration | undefined {
const componentOptions = getNodeOptions(vueInstance) as any as IConfigurable;
if(!componentOptions) {
return;
}
const componentOptions = getNodeOptions(vueInstance) as any as IConfigurable;
if (!componentOptions) {
return;
}

return componentOptions.$_config || (vueInstance as any as IConfigurable).$_config;
return componentOptions.$_config || (vueInstance as any as IConfigurable).$_config;
}

function getInnerChanges(vueInstance: Pick<ComponentPublicInstance, '$'>): any {
const componentOptions = getNodeOptions(vueInstance) as any as IConfigurable;
if(!componentOptions) {
return;
}
const componentOptions = getNodeOptions(vueInstance) as any as IConfigurable;
if (!componentOptions) {
return;
}

return componentOptions.$_innerChanges || (vueInstance as any as IConfigurable).$_innerChanges;
return componentOptions.$_innerChanges || (vueInstance as any as IConfigurable).$_innerChanges;
}

function initOptionChangedFunc(
config,
props: any,
vueInstance: Pick<ComponentPublicInstance, '$' | '$props' | '$emit' | '$options'>,
innerChanges: any,
config,
props: any,
vueInstance: Pick<ComponentPublicInstance, '$' | '$props' | '$emit' | '$options'>,
innerChanges: any,
) {
if(!config) {
return;
}

config.init(Object.keys(props));
if(vueInstance) {
setEmitOptionChangedFunc(config, vueInstance, innerChanges);
}
if (!config) {
return;
}

config.init(Object.keys(props));
if (vueInstance) {
setEmitOptionChangedFunc(config, vueInstance, innerChanges);
}
}

function getComponentInfo({ name, isCollectionItem, ownerConfig }: Configuration, removed?: boolean): IComponentInfo {
const parentPath = ownerConfig && ownerConfig.fullPath;
const optionPath = name && parentPath ? `${parentPath}.${name}` : name || '';

return {
optionPath,
isCollection: isCollectionItem,
removed,
};
const parentPath = ownerConfig && ownerConfig.fullPath;
const optionPath = name && parentPath ? `${parentPath}.${name}` : name || '';

return {
optionPath,
isCollection: isCollectionItem,
removed,
};
}

function initDxConfiguration() {
return defineComponent({
beforeMount() {
const thisComponent = this as any as IConfigurationComponent;
const config = getConfig(thisComponent) as Configuration;
const innerChanges = getInnerChanges(thisComponent);
initOptionChangedFunc(config, getNodeTypeOfComponent(thisComponent).props, thisComponent, innerChanges);
bindOptionWatchers(config, this, innerChanges);
},

mounted() {
if((this.$parent as any).$_instance) {
(this.$parent as any).$_config.componentsCountChanged
.push(getComponentInfo(getConfig(this as any as IConfigurationComponent) as Configuration));
}
},

beforeUnmount() {
const config = getConfig(this as any as IConfigurationComponent) as Configuration;
if(config) {
(this.$parent as any).$_config.componentsCountChanged
.push(getComponentInfo(config, true));
}
},

render(): null {
return null;
},
});
return defineComponent({
beforeMount() {
const thisComponent = this as any as IConfigurationComponent;
const config = getConfig(thisComponent) as Configuration;
const innerChanges = getInnerChanges(thisComponent);
initOptionChangedFunc(config, getNodeTypeOfComponent(thisComponent).props, thisComponent, innerChanges);
bindOptionWatchers(config, this, innerChanges);
},

mounted() {
if ((this.$parent as any).$_instance) {
(this.$parent as any).$_config.componentsCountChanged
.push(getComponentInfo(getConfig(this as any as IConfigurationComponent) as Configuration));
}
},

beforeUnmount() {
const config = getConfig(this as any as IConfigurationComponent) as Configuration;
if (config) {
(this.$parent as any).$_config.componentsCountChanged
.push(getComponentInfo(config, true));
}
},

render(): null {
return null;
},
});
}

export {
initDxConfiguration,
IComponentInfo,
IConfigurable,
IConfigurationComponent,
initOptionChangedFunc,
getConfig,
getInnerChanges,
initDxConfiguration,
IComponentInfo,
IConfigurable,
IConfigurationComponent,
initOptionChangedFunc,
getConfig,
getInnerChanges,
};
3 changes: 0 additions & 3 deletions packages/devextreme-vue/src/core/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable spellcheck/spell-checker */
/* eslint-disable no-prototype-builtins */
/* eslint-disable no-restricted-syntax */
/* eslint-disable import/named */
import {
ComponentPublicInstance as IVue, toRaw, VNode, VNodeProps,
Expand Down
4 changes: 2 additions & 2 deletions packages/devextreme-vue/src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const DX_TEMPLATE_WRAPPER_CLASS = 'dx-template-wrapper';
const DX_REMOVE_EVENT = 'dxremove';

export {
DX_TEMPLATE_WRAPPER_CLASS,
DX_REMOVE_EVENT,
DX_TEMPLATE_WRAPPER_CLASS,
DX_REMOVE_EVENT,
};
39 changes: 19 additions & 20 deletions packages/devextreme-vue/src/core/extension-component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/named */
import { defineComponent } from 'vue';
import { IBaseComponent, initBaseComponent } from './component';
import { getNodeOptions } from './vue-helper';
Expand All @@ -13,28 +12,28 @@ interface IExtensionComponentNode {
}

function initDxExtensionComponent() {
return defineComponent({
extends: initBaseComponent(),
mounted() {
this.$el.setAttribute('isExtension', 'true');
const nodeOptions = getNodeOptions(this);
(nodeOptions as any as IExtension).$_isExtension = true;
(nodeOptions as any as IExtension).$_attachTo = this.attachTo.bind(this);
if(nodeOptions && (nodeOptions as any as IExtensionComponentNode).$_hasOwner) { return; }
return defineComponent({
extends: initBaseComponent(),
mounted() {
this.$el.setAttribute('isExtension', 'true');
const nodeOptions = getNodeOptions(this);
(nodeOptions as any as IExtension).$_isExtension = true;
(nodeOptions as any as IExtension).$_attachTo = this.attachTo.bind(this);
if (nodeOptions && (nodeOptions as any as IExtensionComponentNode).$_hasOwner) { return; }

this.attachTo(this.$el);
},
this.attachTo(this.$el);
},

methods: {
attachTo(element: any) {
(this as any as IBaseComponent).$_createWidget(element);
},
},
});
methods: {
attachTo(element: any) {
(this as any as IBaseComponent).$_createWidget(element);
},
},
});
}

export {
initDxExtensionComponent,
IExtension,
IExtensionComponentNode,
initDxExtensionComponent,
IExtension,
IExtensionComponentNode,
};
Loading

0 comments on commit 74c0320

Please sign in to comment.