Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on vue-formulate 2.5.2 #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 144 additions & 81 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,65 @@ var hooksProp = {
};

//
const {
props,
created, // replace
watch,
computed,
...others
} = Formulate.defaults.components.FormulateInput;

var script = {
extends: Formulate.defaults.components.FormulateInput,
...others,
props: {
...props,
modelHook: {
type: [Function, Object, Array],
default: null,
},
standalone: {
type: Boolean,
default: () => false,
},
},

created() {
this.applyInitialValue();
if (
!this.standalone &&
this.formulateRegister &&
typeof this.formulateRegister === "function"
) {
this.formulateRegister(this.nameOrFallback, this);
}
this.applyDefaultValue();
if (!this.disableErrors && typeof this.observeErrors === "function") {
this.observeErrors({
callback: this.setErrors,
type: "input",
field: this.nameOrFallback,
});
}
this.updateLocalAttributes(this.$attrs);
this.performValidation();
},
computed: {
...computed,
slotProps() {
const fn = this.$formulate.slotProps.bind(this.$formulate);
return {
label: fn(this.type, "label", this.typeProps),
help: fn(this.type, "help", this.typeProps),
errors: fn(this.type, "errors", this.typeProps),
repeatable: fn(this.type, "repeatable", this.typeProps),
addMore: fn(this.type, "addMore", this.typeProps),
remove: fn(this.type, "remove", this.typeProps),
component: fn(this.type, "component", this.typeProps),
};
},
},
watch: {
...watch,
"context.model": {
handler(newModel, oldModel) {
const _modelHook = new Hooks();
Expand All @@ -116,11 +166,20 @@ var script = {
this.$formulate.options.hooks && this.$formulate.options.hooks.model
? this.$formulate.options.hooks.model
: [];

defaultModelHooks.map((h) => _modelHook.addHook(h));

if (newModel !== oldModel) {
this.context.model = _modelHook.apply(newModel, {
oldModel,
let updatedModel = newModel;

if (this.context.classification === "box") {
if (typeof newModel === "string" && newModel.length === 0) {
updatedModel = false;
}
}

if (newModel !== oldModel && _modelHook.hooks.length > 0) {
this.context.model = _modelHook.apply(updatedModel, {
oldModel: oldModel,
context: this.context,
});
}
Expand All @@ -129,79 +188,79 @@ var script = {
},
};

function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
if (typeof shadowMode !== 'boolean') {
createInjectorSSR = createInjector;
createInjector = shadowMode;
shadowMode = false;
}
// Vue.extend constructor export interop.
const options = typeof script === 'function' ? script.options : script;
// render functions
if (template && template.render) {
options.render = template.render;
options.staticRenderFns = template.staticRenderFns;
options._compiled = true;
// functional template
if (isFunctionalTemplate) {
options.functional = true;
}
}
// scopedId
if (scopeId) {
options._scopeId = scopeId;
}
let hook;
if (moduleIdentifier) {
// server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__;
}
// inject component styles
if (style) {
style.call(this, createInjectorSSR(context));
}
// register component module identifier for async chunk inference
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
};
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook;
}
else if (style) {
hook = shadowMode
? function (context) {
style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
}
: function (context) {
style.call(this, createInjector(context));
};
}
if (hook) {
if (options.functional) {
// register for functional component in vue file
const originalRender = options.render;
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return originalRender(h, context);
};
}
else {
// inject component registration as beforeCreate hook
const existing = options.beforeCreate;
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
}
}
return script;
function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
if (typeof shadowMode !== 'boolean') {
createInjectorSSR = createInjector;
createInjector = shadowMode;
shadowMode = false;
}
// Vue.extend constructor export interop.
const options = typeof script === 'function' ? script.options : script;
// render functions
if (template && template.render) {
options.render = template.render;
options.staticRenderFns = template.staticRenderFns;
options._compiled = true;
// functional template
if (isFunctionalTemplate) {
options.functional = true;
}
}
// scopedId
if (scopeId) {
options._scopeId = scopeId;
}
let hook;
if (moduleIdentifier) {
// server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__;
}
// inject component styles
if (style) {
style.call(this, createInjectorSSR(context));
}
// register component module identifier for async chunk inference
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
};
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook;
}
else if (style) {
hook = shadowMode
? function (context) {
style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
}
: function (context) {
style.call(this, createInjector(context));
};
}
if (hook) {
if (options.functional) {
// register for functional component in vue file
const originalRender = options.render;
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return originalRender(h, context);
};
}
else {
// inject component registration as beforeCreate hook
const existing = options.beforeCreate;
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
}
}
return script;
}

/* script */
Expand Down Expand Up @@ -425,7 +484,7 @@ function leaf(item, index, { hooks, h, state } = {}) {
.addHook(modelHook)
.asSingleHook();

const node = Object.assign({ type, key, depth, component, definition: { attrs: { ...attrs, modelHook: _modelHook } }, children: tree(els, { hooks, h, state }) });
const node = Object.assign({ name, type, key, depth, component, definition: { attrs: { ...attrs, modelHook: _modelHook } }, children: tree(els, { hooks, h, state }) });

return new Hooks()
.setHooks(hooks.schemaNode)
Expand Down Expand Up @@ -513,11 +572,11 @@ var script$1 = {
new Set(Object.keys(values).concat(Object.keys(this.proxy)))
);
keys.forEach((field) => {
if (!utils_js.shallowEqualObjects(values[field], this.proxy[field])) {
if (!utils_js.equals(values[field], this.proxy[field])) {
this.setFieldValue(field, values[field]);
if (
this.registry.has(field) &&
!utils_js.shallowEqualObjects(
!utils_js.equals(
values[field],
this.registry.get(field).proxy
)
Expand Down Expand Up @@ -713,7 +772,7 @@ var enforceNumber = {
};

const components = { FormulateForm: __vue_component__$1, FormulateSchema, FormulateInput: __vue_component__ };
const features = { formEvents, textMask, enforceNumber };
const features = { formEvents, enforceNumber, textMask }; // textMask - need to be removed to avoid required dependency

function index(options = {}) {
let extended = {
Expand Down Expand Up @@ -753,6 +812,10 @@ function index(options = {}) {

if (extended.options.features.textMask) {
instance.extend(textMask);
// lazy loaded
// import('./features/text-mask').then((textMask) => {
// instance.extend(textMask.default)
// })
}

if (extended.options.features.enforceNumber) {
Expand Down
Loading