From dfa2186ee914044b323b8e5a97501f9d941c0710 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Barfleur?=
<39409397+kevinbarfleur@users.noreply.github.com>
Date: Tue, 12 Nov 2024 14:59:29 +0100
Subject: [PATCH 1/8] Add element-event to use this element in
ww-select-input-search
---
src/wwElement.vue | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/wwElement.vue b/src/wwElement.vue
index 8fd5a17..e58b257 100644
--- a/src/wwElement.vue
+++ b/src/wwElement.vue
@@ -59,7 +59,7 @@ export default {
uid: { type: String, required: true },
wwElementState: { type: Object, required: true },
},
- emits: ['trigger-event', 'add-state', 'remove-state', 'update:content:effect'],
+ emits: ['element-event', 'trigger-event', 'add-state', 'remove-state', 'update:content:effect'],
setup(props) {
const type = computed(() => {
if (Object.keys(props.wwElementState.props).includes('type')) {
@@ -258,10 +258,14 @@ export default {
name: 'change',
event: { domEvent: event, value: newValue },
});
+ // element-event is useful when using inputs inside other coded components.
+ // See ww-select-input-search => https://github.com/weweb-assets/ww-input-select-search
+ this.$emit('element-event', { type: 'change', value: { domEvent: event, value: newValue } });
this.isDebouncing = false;
}, this.delay);
} else {
this.$emit('trigger-event', { name: 'change', event: { domEvent: event, value: newValue } });
+ this.$emit('element-event', { type: 'change', value: { domEvent: event, value: newValue } });
}
},
onKeyEnter(event) {
From 57dc6f07329d978a6b4e1675e7b59cbad05c4c6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Barfleur?=
<39409397+kevinbarfleur@users.noreply.github.com>
Date: Tue, 12 Nov 2024 19:31:46 +0100
Subject: [PATCH 2/8] Parent selection
---
src/wwElement.vue | 35 ++++++++++++++++++++++++++++++++---
ww-config.js | 21 +++++++++++++++++++++
2 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/src/wwElement.vue b/src/wwElement.vue
index e58b257..e63f767 100644
--- a/src/wwElement.vue
+++ b/src/wwElement.vue
@@ -47,7 +47,7 @@
diff --git a/ww-config.js b/ww-config.js
index 72f869e..934c8c4 100644
--- a/ww-config.js
+++ b/ww-config.js
@@ -29,6 +29,21 @@ export default {
'resize',
],
],
+ hint: (_, sidePanelContent) => {
+ if (!sidePanelContent.parentSelection) return null;
+ const { header, text, button, args } = sidePanelContent.parentSelection;
+ const sections = ['style', 'settings'];
+ return sections.map(section => ({
+ section,
+ header: header,
+ text: text,
+ button: {
+ text: button,
+ action: 'selectParentElement',
+ args,
+ },
+ }));
+ },
},
states: ['focus', 'readonly'],
actions: [{ label: 'Focus element', action: 'focusInput' }],
@@ -340,5 +355,11 @@ export default {
},
/* wwEditor:end */
},
+ /* wwEditor:start */
+ parentSelection: {
+ editorOnly: true,
+ defaultValue: false,
+ },
+ /* wwEditor:end */
},
};
From 807ad7eefe24a37857efe384db7793c459f5b573 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Barfleur?=
<39409397+kevinbarfleur@users.noreply.github.com>
Date: Wed, 13 Nov 2024 09:21:30 +0100
Subject: [PATCH 3/8] Refactor
---
src/editor/useParentSelection.js | 23 +++++++++++++++++++++++
src/wwElement.vue | 24 ++++++++----------------
ww-config.js | 2 +-
3 files changed, 32 insertions(+), 17 deletions(-)
create mode 100644 src/editor/useParentSelection.js
diff --git a/src/editor/useParentSelection.js b/src/editor/useParentSelection.js
new file mode 100644
index 0000000..ebcb641
--- /dev/null
+++ b/src/editor/useParentSelection.js
@@ -0,0 +1,23 @@
+import { computed, watch } from 'vue';
+
+export default function useParentSelection(props, emit) {
+ const parentSelection = computed(() => props.parentSelection);
+
+ function selectParentElement(el, ...args) {
+ wwLib.selectParentByFlag(el, ...args);
+ }
+
+ watch(
+ parentSelection,
+ parentSelection => {
+ if (parentSelection.allow && parentSelection.info) {
+ emit('update:sidepanel-content', { path: 'parentSelection', value: parentSelection.info });
+ } else {
+ emit('update:sidepanel-content', { path: 'parentSelection', value: null });
+ }
+ },
+ { immediate: true, deep: true }
+ );
+
+ return { selectParentElement };
+}
diff --git a/src/wwElement.vue b/src/wwElement.vue
index e63f767..cdaeb99 100644
--- a/src/wwElement.vue
+++ b/src/wwElement.vue
@@ -47,7 +47,10 @@
-
-
diff --git a/src/wwElement_InputBasic.vue b/src/wwElement_InputBasic.vue
new file mode 100644
index 0000000..bb134ea
--- /dev/null
+++ b/src/wwElement_InputBasic.vue
@@ -0,0 +1,201 @@
+
+
+
+
+
+
+
+
diff --git a/ww-config.js b/ww-config.js
index dffd4cc..a8cd3e7 100644
--- a/ww-config.js
+++ b/ww-config.js
@@ -7,13 +7,18 @@ export default {
label: { en: 'Form Input', fr: 'Entrée de Formulaire' },
icon: 'text-input',
customSettingsPropertiesOrder: [
+ 'formInfobox',
+ ['fieldName', 'customValidation', 'validation'],
+ 'type',
'value',
- ['placeholder'],
- ['readonly', 'required'],
- ['debounce', 'debounceDelay'],
+ 'placeholder',
+ 'readonly',
+ 'required',
+ 'autocomplete',
+ 'debounce',
+ 'debounceDelay',
],
customStylePropertiesOrder: [
- 'type',
'placeholderColor',
[
'precision',
@@ -361,5 +366,47 @@ export default {
defaultValue: false,
},
/* wwEditor:end */
+ /* wwEditor:start */
+ form: {
+ editorOnly: true,
+ hidden: true,
+ defaultValue: false,
+ },
+ formInfobox: {
+ type: 'InfoBox',
+ section: 'settings',
+ options: (_, sidePanelContent) => ({
+ variant: sidePanelContent.form?.name ? 'success' : 'warning',
+ icon: 'pencil',
+ title: sidePanelContent.form?.name || 'Unnamed form',
+ content: !sidePanelContent.form?.name && 'Give your form a meaningful name.',
+ }),
+ hidden: (_, sidePanelContent) => !sidePanelContent.form?.uid,
+ },
+ /* wwEditor:end */
+ fieldName: {
+ label: 'Field name',
+ section: 'settings',
+ type: 'Text',
+ defaultValue: '',
+ bindable: true,
+ hidden: (_, sidePanelContent) => !sidePanelContent.form?.uid,
+ },
+ customValidation: {
+ label: 'Custom validation',
+ section: 'settings',
+ type: 'OnOff',
+ defaultValue: false,
+ bindable: true,
+ hidden: (_, sidePanelContent) => !sidePanelContent.form?.uid,
+ },
+ validation: {
+ label: 'Validation',
+ section: 'settings',
+ type: 'Formula',
+ defaultValue: '',
+ bindable: true,
+ hidden: (content, sidePanelContent) => !sidePanelContent.form?.uid || !content.customValidation,
+ },
},
};
From 29951b1cd9357a9439d7715e87bd4b2645e23128 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Barfleur?=
<39409397+kevinbarfleur@users.noreply.github.com>
Date: Tue, 19 Nov 2024 07:09:33 +0100
Subject: [PATCH 6/8] Renaming
---
src/wwElement_InputBasic.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/wwElement_InputBasic.vue b/src/wwElement_InputBasic.vue
index bb134ea..f1754fd 100644
--- a/src/wwElement_InputBasic.vue
+++ b/src/wwElement_InputBasic.vue
@@ -79,7 +79,7 @@ export default {
onBlur,
} = useInput(props, emit);
- const useForm = inject('wwUseForm', () => {});
+ const useForm = inject('_wwForm:useForm', () => {});
useForm(
variableValue,
{
From 7ebab57b75dc787f7d1ab94ca82be7211fadcd9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Barfleur?=
<39409397+kevinbarfleur@users.noreply.github.com>
Date: Tue, 19 Nov 2024 11:40:36 +0100
Subject: [PATCH 7/8] test
---
src/wwElement_InputBasic.vue | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/wwElement_InputBasic.vue b/src/wwElement_InputBasic.vue
index f1754fd..81e91d7 100644
--- a/src/wwElement_InputBasic.vue
+++ b/src/wwElement_InputBasic.vue
@@ -80,14 +80,25 @@ export default {
} = useInput(props, emit);
const useForm = inject('_wwForm:useForm', () => {});
- useForm(
- variableValue,
- {
- fieldName: props.content.fieldName,
- validation: props.content.validation,
- customValidation: props.content.customValidation,
+
+ const fieldName = computed(() => props.content.fieldName);
+ const validation = computed(() => props.content.validation);
+ const customValidation = computed(() => props.content.customValidation);
+
+ watch(
+ () => [fieldName.value, validation.value, customValidation.value],
+ () => {
+ useForm(
+ variableValue,
+ {
+ fieldName: fieldName.value,
+ validation: validation.value,
+ customValidation: customValidation.value,
+ },
+ { elementState: props.wwElementState, emit, sidepanelFormPath: 'form' }
+ );
},
- { elementState: props.wwElementState, emit, sidepanelFormPath: 'form' }
+ { immediate: true, deep: true }
);
const inputBindings = computed(() => ({
From 260b5bbe33df77305bc7c353d8dbd6eb2968b24a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Barfleur?=
<39409397+kevinbarfleur@users.noreply.github.com>
Date: Tue, 19 Nov 2024 12:16:58 +0100
Subject: [PATCH 8/8] Fix useForm
---
src/wwElement_InputBasic.vue | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/src/wwElement_InputBasic.vue b/src/wwElement_InputBasic.vue
index 81e91d7..f586a66 100644
--- a/src/wwElement_InputBasic.vue
+++ b/src/wwElement_InputBasic.vue
@@ -85,20 +85,10 @@ export default {
const validation = computed(() => props.content.validation);
const customValidation = computed(() => props.content.customValidation);
- watch(
- () => [fieldName.value, validation.value, customValidation.value],
- () => {
- useForm(
- variableValue,
- {
- fieldName: fieldName.value,
- validation: validation.value,
- customValidation: customValidation.value,
- },
- { elementState: props.wwElementState, emit, sidepanelFormPath: 'form' }
- );
- },
- { immediate: true, deep: true }
+ useForm(
+ variableValue,
+ { fieldName, validation, customValidation },
+ { elementState: props.wwElementState, emit, sidepanelFormPath: 'form' }
);
const inputBindings = computed(() => ({