protected createMiniComponents()

in packages/shared/src/miniapp/template.ts [113:202]


  protected createMiniComponents(components: Components) {
    const result: Components = Object.create(null);

    for (const key in components) {
      if (hasOwn(components, key)) {
        let component = components[key];
        const compName = toDashed(key);
        const newComp: Record<string, string> = Object.create(null);
        const componentAlias = this.componentsAlias[compName];

        if (isFunction(this.modifyCompProps)) {
          component = this.modifyCompProps(compName, component);
        }

        for (let prop in component) {
          if (hasOwn(component, prop)) {
            let propValue = component[prop];
            if (prop.startsWith('bind') || propValue === 'eh') {
              propValue = 'eh';
            } else if (propValue === '') {
              const propInCamelCase = toCamelCase(prop);
              const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
              propValue = `i.${propAlias}`;
            } else if (isBooleanStringLiteral(propValue) || isNumber(+propValue)) {
              const propInCamelCase = toCamelCase(prop);
              const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
              propValue = this.supportXS
                ? `xs.b(i.${propAlias},${propValue})`
                : `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
            } else {
              const propInCamelCase = toCamelCase(prop);
              const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
              propValue = `i.${propAlias}||${propValue || singleQuote('')}`;
            }

            prop = this.replacePropName(prop, propValue, compName, componentAlias);

            newComp[prop] = propValue;
          }
        }
        if (compName !== 'block') {
          Object.assign(newComp, styles, this.getEvents());
        }

        if (compName === 'swiper-item') {
          delete newComp.style;
        }

        if (compName === 'view') {
          const reg = /^(bind|on)(touchmove|TouchMove)$/;
          const comp = { ...newComp };
          Object.keys(comp).forEach(originKey => {
            if (!reg.test(originKey)) return;

            const key = originKey.replace(reg, 'catch$2');
            comp[key] = comp[originKey];
            delete comp[originKey];
          });

          result['catch-view'] = comp;
        }

        if (compName === 'view' || compName === 'text' || compName === 'image') {
          const comp: Record<any, any> = {};
          Object.keys(newComp).forEach(key => {
            const value = newComp[key];
            if (value !== 'eh') comp[key] = value;
          });
          result[`static-${compName}`] = comp;
          if (compName === 'view') {
            result['pure-view'] = {
              style: comp.style,
              class: comp.class,
            };
          }
        }

        if (compName === 'slot' || compName === 'slot-view') {
          result[compName] = {
            slot: newComp?.name,
            ...styles,
          };
        } else {
          result[compName] = newComp;
        }
      }
    }

    return result;
  }