From c7e7d448c43340c045da9956e7e51934536e42a6 Mon Sep 17 00:00:00 2001
From: dmh <5150636+dmh@users.noreply.github.com>
Date: Tue, 25 Jun 2024 16:27:45 +0300
Subject: [PATCH] [TASK] general refactor, use fields types from hubspot react
modules
---
.gitignore | 1 +
.husky/pre-commit | 4 -
index.js | 70 +-
lib/content-tab-fields.js | 703 +++--
lib/fields.js | 289 +-
lib/group.js | 84 +-
lib/init.js | 80 +-
lib/style-tab-fields.js | 285 +-
lib/types/namespaces.js | 6 +-
lib/types/types.js | 654 +++-
lib/utils/common-properties.js | 91 -
lib/utils/initField.js | 57 -
package-lock.json | 1587 +++++++---
package.json | 21 +-
partials/all.js | 30 -
partials/button.js | 56 -
partials/heading.js | 190 --
partials/icon.js | 128 -
partials/image.js | 65 -
partials/link.js | 49 -
partials/richtext.js | 61 -
partials/secondary-button.js | 55 -
partials/secondary-link.js | 51 -
partials/subheading.js | 134 -
partials/text.js | 90 -
test/1content-js-simple.module/fields.js | 22 -
test/1content-js-simple.module/fields.json | 184 --
test/1content-js.module/fields.js | 102 -
test/1content-js.module/fields.json | 231 --
test/1content-js.module/meta.json | 6 -
test/1content-js.module/module.css | 1 -
test/1content-js.module/module.html | 0
test/1content-js.module/module.js | 0
test/1contentgroup-js-simple.module/fields.js | 17 -
.../fields.json | 54 -
test/1contentgroup-js-simple.module/meta.json | 6 -
.../1contentgroup-js-simple.module/module.css | 1 -
.../module.html | 0
test/1contentgroup-js-simple.module/module.js | 0
test/1partials-js.module/fields.js | 36 -
test/1partials-js.module/fields.json | 2640 -----------------
test/1partials-js.module/meta.json | 6 -
test/1partials-js.module/module.css | 1 -
test/1partials-js.module/module.html | 0
test/1partials-js.module/module.js | 0
test/1style-js-simple.module/fields.js | 26 -
test/1style-js-simple.module/fields.json | 192 --
test/1style-js-simple.module/meta.json | 6 -
test/1style-js-simple.module/module.css | 1 -
test/1style-js-simple.module/module.html | 0
test/1style-js-simple.module/module.js | 0
test/1style-js.module/fields.js | 140 -
test/1style-js.module/fields.json | 283 --
test/1style-js.module/meta.json | 6 -
test/1style-js.module/module.css | 1 -
test/1style-js.module/module.html | 0
test/1style-js.module/module.js | 0
test/all-fields.module/fields.js | 63 +
test/all-fields.module/fields.json | 226 ++
.../meta.json | 0
.../module.css | 0
.../module.html | 0
.../module.js | 0
.../2content-simple.module/fields.json | 135 -
test/hubspot/2content-simple.module/meta.json | 6 -
.../hubspot/2content-simple.module/module.css | 0
.../2content-simple.module/module.html | 0
test/hubspot/2content-simple.module/module.js | 0
test/hubspot/2content.module/fields.json | 184 --
test/hubspot/2content.module/meta.json | 6 -
test/hubspot/2content.module/module.css | 1 -
test/hubspot/2content.module/module.html | 0
test/hubspot/2content.module/module.js | 0
test/hubspot/2style-simple.module/fields.json | 169 --
test/hubspot/2style-simple.module/meta.json | 6 -
test/hubspot/2style-simple.module/module.css | 0
test/hubspot/2style-simple.module/module.html | 0
test/hubspot/2style-simple.module/module.js | 0
test/hubspot/2style.module/fields.json | 392 ---
test/hubspot/2style.module/meta.json | 6 -
test/hubspot/2style.module/module.css | 1 -
test/hubspot/2style.module/module.html | 0
test/hubspot/2style.module/module.js | 0
83 files changed, 2712 insertions(+), 7286 deletions(-)
delete mode 100644 lib/utils/common-properties.js
delete mode 100644 lib/utils/initField.js
delete mode 100644 partials/all.js
delete mode 100644 partials/button.js
delete mode 100644 partials/heading.js
delete mode 100644 partials/icon.js
delete mode 100644 partials/image.js
delete mode 100644 partials/link.js
delete mode 100644 partials/richtext.js
delete mode 100644 partials/secondary-button.js
delete mode 100644 partials/secondary-link.js
delete mode 100644 partials/subheading.js
delete mode 100644 partials/text.js
delete mode 100644 test/1content-js-simple.module/fields.js
delete mode 100644 test/1content-js-simple.module/fields.json
delete mode 100644 test/1content-js.module/fields.js
delete mode 100644 test/1content-js.module/fields.json
delete mode 100644 test/1content-js.module/meta.json
delete mode 100644 test/1content-js.module/module.css
delete mode 100644 test/1content-js.module/module.html
delete mode 100644 test/1content-js.module/module.js
delete mode 100644 test/1contentgroup-js-simple.module/fields.js
delete mode 100644 test/1contentgroup-js-simple.module/fields.json
delete mode 100644 test/1contentgroup-js-simple.module/meta.json
delete mode 100644 test/1contentgroup-js-simple.module/module.css
delete mode 100644 test/1contentgroup-js-simple.module/module.html
delete mode 100644 test/1contentgroup-js-simple.module/module.js
delete mode 100644 test/1partials-js.module/fields.js
delete mode 100644 test/1partials-js.module/fields.json
delete mode 100644 test/1partials-js.module/meta.json
delete mode 100644 test/1partials-js.module/module.css
delete mode 100644 test/1partials-js.module/module.html
delete mode 100644 test/1partials-js.module/module.js
delete mode 100644 test/1style-js-simple.module/fields.js
delete mode 100644 test/1style-js-simple.module/fields.json
delete mode 100644 test/1style-js-simple.module/meta.json
delete mode 100644 test/1style-js-simple.module/module.css
delete mode 100644 test/1style-js-simple.module/module.html
delete mode 100644 test/1style-js-simple.module/module.js
delete mode 100644 test/1style-js.module/fields.js
delete mode 100644 test/1style-js.module/fields.json
delete mode 100644 test/1style-js.module/meta.json
delete mode 100644 test/1style-js.module/module.css
delete mode 100644 test/1style-js.module/module.html
delete mode 100644 test/1style-js.module/module.js
create mode 100644 test/all-fields.module/fields.js
create mode 100644 test/all-fields.module/fields.json
rename test/{1content-js-simple.module => all-fields.module}/meta.json (100%)
rename test/{1content-js-simple.module => all-fields.module}/module.css (100%)
rename test/{1content-js-simple.module => all-fields.module}/module.html (100%)
rename test/{1content-js-simple.module => all-fields.module}/module.js (100%)
delete mode 100644 test/hubspot/2content-simple.module/fields.json
delete mode 100644 test/hubspot/2content-simple.module/meta.json
delete mode 100644 test/hubspot/2content-simple.module/module.css
delete mode 100644 test/hubspot/2content-simple.module/module.html
delete mode 100644 test/hubspot/2content-simple.module/module.js
delete mode 100644 test/hubspot/2content.module/fields.json
delete mode 100644 test/hubspot/2content.module/meta.json
delete mode 100644 test/hubspot/2content.module/module.css
delete mode 100644 test/hubspot/2content.module/module.html
delete mode 100644 test/hubspot/2content.module/module.js
delete mode 100644 test/hubspot/2style-simple.module/fields.json
delete mode 100644 test/hubspot/2style-simple.module/meta.json
delete mode 100644 test/hubspot/2style-simple.module/module.css
delete mode 100644 test/hubspot/2style-simple.module/module.html
delete mode 100644 test/hubspot/2style-simple.module/module.js
delete mode 100644 test/hubspot/2style.module/fields.json
delete mode 100644 test/hubspot/2style.module/meta.json
delete mode 100644 test/hubspot/2style.module/module.css
delete mode 100644 test/hubspot/2style.module/module.html
delete mode 100644 test/hubspot/2style.module/module.js
diff --git a/.gitignore b/.gitignore
index c1a2ce8..63ae2de 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ node_modules
.env*
.idea
.tmp
+.DS_Store
diff --git a/.husky/pre-commit b/.husky/pre-commit
index 4536f86..72c4429 100755
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1,5 +1 @@
-#!/bin/sh
-. "$(dirname "$0")/_/husky.sh"
-
npm test
-npm run docs
diff --git a/index.js b/index.js
index 4da5152..92c5f6d 100644
--- a/index.js
+++ b/index.js
@@ -1,31 +1,8 @@
-import { init, writeJson } from './lib/init.js'
+import { init } from './lib/init.js'
import { group, styleGroup } from './lib/group.js'
-import {
- alignment,
- spacing,
- gradient,
- backgroundimage,
- border,
- textalignment
-} from './lib/style-tab-fields.js'
-import {
- boolean,
- choice,
- number,
- color,
- icon,
- image,
- font
-} from './lib/fields.js'
-import {
- text,
- link,
- richtext,
- url,
- video,
- embed,
- cta
-} from './lib/content-tab-fields.js'
+import * as styleTabFields from './lib/style-tab-fields.js'
+import * as fields from './lib/fields.js'
+import * as contentTabFields from './lib/content-tab-fields.js'
/**
* #### Module fields entry point
@@ -33,41 +10,20 @@ import {
* @constant
*/
const moduleFields = {
- text,
- link,
- richtext,
- url,
- boolean,
- choice,
- number,
- color,
- icon,
- image,
- font,
- alignment,
- spacing,
- gradient,
- backgroundimage,
- border,
- textalignment,
- video,
- embed,
- cta
+ ...contentTabFields,
+ ...styleTabFields,
+ ...fields
}
+
/**
* #### Theme fields entry point
* @ignore
* @constant
- */
+*/
const themeFields = {
- boolean,
- choice,
- number,
- color,
- image,
- font,
- spacing,
- border
+ ...fields,
+ ...styleTabFields.spacing,
+ ...styleTabFields.border
}
-export { moduleFields, themeFields, group, styleGroup, init, writeJson }
+export { moduleFields, themeFields, group, styleGroup, init }
diff --git a/lib/content-tab-fields.js b/lib/content-tab-fields.js
index 3def760..636c5a7 100644
--- a/lib/content-tab-fields.js
+++ b/lib/content-tab-fields.js
@@ -1,15 +1,4 @@
-import * as TYPES from './types/types.js' // eslint-disable-line
-import { initField } from './utils/initField.js'
-
-/**
- * @ignore
- * @typedef {TYPES.EDITOR_OPTIONS} EDITOR_OPTIONS {@link EDITOR_OPTIONS}
- * @typedef {TYPES.DISPLAY_CONDITIONS} DISPLAY_CONDITIONS {@link DISPLAY_CONDITIONS}
- * @typedef {TYPES.REPEATER_OPTIONS} REPEATER_OPTIONS {@link REPEATER_OPTIONS}
- * @typedef {TYPES.REPEATER_OPTIONS_DEFAULT} REPEATER_OPTIONS_DEFAULT {@link REPEATER_OPTIONS_DEFAULT}
- * @typedef {TYPES.COMMON_FIELDS} COMMON_FIELDS {@link COMMON_FIELDS}
- */
-
+///
// *************
// Only Content Tab fields
// *************
@@ -17,256 +6,590 @@ import { initField } from './utils/initField.js'
/**
* #### Text fields provide content creators a simple text editing experience with no rich text functionality. Text fields initially show as a single line, but can actually expand to be textareas, supporting multiple lines.
* `only_content_tab`
- *
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
* @example
* fi.text('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {string} [fields.validation_regex] Regex pattern to validate the input
- * @param {boolean} [fields.allow_new_line=false] `false` Allows new line
- * @param {boolean} [fields.show_emoji_picker] `false` Shows emoji picker
- * @param {string} [fields.placeholder] Placeholder text
- * @param {string} [fields.default] Text string --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|TEXT_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
function text (label, name, fields) {
- const contentOptions = {}
- contentOptions.allow_new_line = fields?.allow_new_line ?? false
- contentOptions.show_emoji_picker = fields?.show_emoji_picker ?? false
- contentOptions.validation_regex = fields?.validation_regex ?? ''
- if (typeof fields !== 'undefined' && fields !== null && typeof fields === 'object') {
- if ('placeholder' in fields) contentOptions.placeholder = fields.placeholder
- if ('default' in fields) contentOptions.default = fields.default
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'text' }
+ }
+}
+
+/**
+ * #### Audioplayer field
+ * `only_content_tab`
+ * @example
+ * fi.audioplayer('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|AUDIO_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function audioplayer (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'audioplayer' }
+ }
+}
+
+/**
+ * #### Blog field
+ * `only_content_tab`
+ * @example
+ * fi.blog('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|BLOG_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function blog (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'blog' }
+ }
+}
+
+/**
+ * #### crmobject field
+ * `only_content_tab`
+ * @example
+ * fi.crmobject('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|CRM_OBJECT_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function crmobject (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'crmobject' }
+ }
+}
+
+/**
+ * #### crmobjectproperty field
+ * `only_content_tab`
+ * @example
+ * fi.crmobjectproperty('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|CRM_OBJECT_PROPERTY_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function crmobjectproperty (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'crmobjectproperty' }
+ }
+}
+
+/**
+ * #### cta field
+ * `only_content_tab`
+ * @example
+ * fi.cta('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|CTA_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function cta (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'cta' }
+ }
+}
+
+/**
+ * #### date field
+ * `only_content_tab`
+ * @example
+ * fi.date('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|DATE_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function date (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'date' }
+ }
+}
+
+/**
+ * #### datetime field
+ * `only_content_tab`
+ * @example
+ * fi.datetime('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|DATA_AND_TIME_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function datetime (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'datetime' }
+ }
+}
+
+/**
+ * #### email field
+ * `only_content_tab`
+ * @example
+ * fi.email('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|EMAIL_ADDRESS_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function email (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'email' }
+ }
+}
+
+/**
+ * #### embed field
+ * `only_content_tab`
+ * @example
+ * fi.embed('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|EMBEDED_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function embed (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'embed' }
+ }
+}
+
+/**
+ * #### file field
+ * `only_content_tab`
+ * @example
+ * fi.file('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|FILE_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function file (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'file' }
+ }
+}
+
+/**
+ * #### form field
+ * `only_content_tab`
+ * @example
+ * fi.form('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|FORM_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function form (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'form' }
}
+}
- const otherOptions = initField(label, name, 'text', fields)
- return { ...contentOptions, ...otherOptions }
+/**
+ * #### html field
+ * `only_content_tab`
+ * @example
+ * fi.html('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|HTML_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function html (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'html' }
+ }
}
/**
- * @typedef {Object} LINK_DEFAULT
- * @property {Object} [url] Default URL object
- * @property {?string} [url.content_id] Default URL content ID
- * @property {'EXTERNAL'|'CONTENT'|'FILE'|'EMAIL_ADDRESS'|'BLOG'|'CALL_TO_ACTION'|'PHONE_NUMBER'|'WHATSAPP_NUMBER'} [url.type] Default URL type
- * @property {string} [url.href] Default URL href
- * @property {boolean} [open_in_new_tab] Default open_in_new_tab value
- * @property {boolean} [no_follow] Default no_follow value
- * @property {boolean} [sponsored] Default sponsored value
- * @property {boolean} [user_generated_content] Default user_generated_content value
+ * #### hubdbrow field
+ * `only_content_tab`
+ * @example
+ * fi.hubdbrow('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|HUBDB_ROW_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
*/
+function hubdbrow (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'hubdbrow' }
+ }
+}
/**
- * @typedef {'EXTERNAL'|'CONTENT'|'FILE'|'EMAIL_ADDRESS'|'BLOG'|'CALL_TO_ACTION'|'PHONE_NUMBER'|'WHATSAPP_NUMBER'} LINK_SUPPORTED_TYPES
+ * #### hubdbtable field
+ * `only_content_tab`
+ * @example
+ * fi.hubdbtable('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|HUBDB_TABLE_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
*/
+function hubdbtable (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'hubdbtable' }
+ }
+}
/**
- * #### Link fields provide an easy interface for content creators to provide links to URLs and email addresses.
+ * #### hubl field
+ * `only_content_tab`
+ * @example
+ * fi.hubl('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|HUBL_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function hubl (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'hubl' }
+ }
+}
+
+/**
+ * #### menu field
+ * `only_content_tab`
+ * @example
+ * fi.menu('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|MENU_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function menu (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'menu' }
+ }
+}
+
+/**
+ * #### meeting field
+ * `only_content_tab`
+ * @example
+ * fi.meeting('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|MEETING_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function meeting (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'meeting' }
+ }
+}
+
+/**
+ * #### logo field
+ * `only_content_tab`
+ * @example
+ * fi.logo('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|LOGO_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function logo (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'logo' }
+ }
+}
+
+/**
+ * #### link field
* `only_content_tab`
- *
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
* @example
* fi.link('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {Array} [fields.supported_types=all] `all` list of the types of links this field allows content creators to select
- * @param {boolean} [fields.show_advanced_rel_options=false] `false` Whether content creators can see advanced rel options
- * @param {LINK_DEFAULT} [fields.default] Default object --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|LINK_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
function link (label, name, fields) {
- const contentOptions = {}
- contentOptions.show_advanced_rel_options = fields?.show_advanced_rel_options ?? false
- contentOptions.supported_types = fields?.supported_types ?? ['EXTERNAL', 'CONTENT', 'FILE', 'EMAIL_ADDRESS', 'BLOG', 'CALL_TO_ACTION', 'PHONE_NUMBER', 'WHATSAPP_NUMBER']
- /**
- * @type {LINK_DEFAULT}
- */
- const defaultObj = {
- url: {
- content_id: null,
- type: 'EXTERNAL',
- href: ''
- },
- open_in_new_tab: false,
- no_follow: false
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'link' }
}
- contentOptions.default = { ...defaultObj, ...fields?.default }
- contentOptions.default.url = { ...defaultObj.url, ...fields?.default?.url }
-
- const otherOptions = initField(label, name, 'link', fields)
- return { ...contentOptions, ...otherOptions }
}
/**
- * #### Rich Text fields provide content creators with a WYSIWYG text editor experience.
+ * #### richtext field
* `only_content_tab`
- *
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
* @example
* fi.richtext('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {Array} [fields.enabled_features] An array of items that allows you to configure the Rich Text Editor Toolbar and what options are available for content editors.
- * @param {string} [fields.default] String of content to be displayed supports HTML --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|RICHTEXT_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
function richtext (label, name, fields) {
- const contentOptions = {}
- if (typeof fields !== 'undefined' && fields !== null && typeof fields === 'object') {
- if ('enabled_features' in fields) contentOptions.enabled_features = fields.enabled_features
- if ('default' in fields) contentOptions.default = fields.default
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'richtext' }
}
-
- const otherOptions = initField(label, name, 'richtext', fields)
- return { ...contentOptions, ...otherOptions }
}
/**
- * #### URL fields provide a similar experience to link fields. Providing a UI for content creators to add links. URL fields, however, do not show a UI for open in a new window, nor tell search engines not to follow. Use this field when you as a developer want to dictate the values for that.
+ * #### simplemenu field
* `only_content_tab`
- *
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
* @example
- * fi.url('label', 'name', {...options if needed})
+ * fi.simplemenu('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {Array} [fields.supported_types=all] `all` list of the types of links this field allows content creators to select.
- * @param {Object} [fields.default] Default object --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {string} [fields.default.content_id] Default content id
- * @param {'EXTERNAL'|'CONTENT'|'FILE'|'EMAIL_ADDRESS'|'BLOG'|'CALL_TO_ACTION'|'PHONE_NUMBER'|'WHATSAPP_NUMBER'} fields.default.type Default URL type
- * @param {string} [fields.default.href] Default href
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|SIMPLE_MENU_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
-function url (label, name, fields) {
- const contentOptions = {}
- contentOptions.supported_types = fields?.supported_types ?? ['EXTERNAL', 'CONTENT', 'FILE', 'EMAIL_ADDRESS', 'BLOG', 'CALL_TO_ACTION', 'PHONE_NUMBER', 'WHATSAPP_NUMBER']
- const defaultObj = {
- content_id: null,
- href: '',
- type: 'EXTERNAL'
+function simplemenu (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'simplemenu' }
}
- contentOptions.default = { ...defaultObj, ...fields?.default }
+}
- const otherOptions = initField(label, name, 'url', fields)
- return { ...contentOptions, ...otherOptions }
+/**
+ * #### podcast field
+ * `only_content_tab`
+ * @example
+ * fi.podcast('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|PODCAST_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function podcast (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'podcast' }
+ }
}
/**
- * #### Video fields provide content editors with a place to add HubSpot Video to their module content without the need of using rich text fields.
+ * #### payment field
* `only_content_tab`
- *
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
* @example
- * fi.video('label', 'name', {...options if needed})
+ * fi.payment('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {boolean} [fields.resizable=true] `true` Whether the video is resizable
- * @param {boolean} [fields.show_preview=true] `true` Whether the video is previewable
- * @param {boolean} [fields.show_advanced_options=true] `true` Whether the video is advanced options
- * @param {Object} [fields.default] Default object --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|PAYMENT_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
-function video (label, name, fields) {
- const contentOptions = {}
- contentOptions.resizable = fields?.resizable ?? true
- contentOptions.show_preview = fields?.show_preview ?? true
- contentOptions.show_advanced_options = fields?.show_advanced_options ?? true
- contentOptions.default = fields?.default ?? {}
+function payment (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'payment' }
+ }
+}
- const otherOptions = initField(label, name, 'videoplayer', fields)
- return { ...contentOptions, ...otherOptions }
+/**
+ * #### page field
+ * `only_content_tab`
+ * @example
+ * fi.page('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|PAGE_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function page (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'page' }
+ }
}
/**
- * #### Embed fields allow the user to add a URL from an oEmbed-enabled site or paste in an embed code from another site.
+ * #### tag field
* `only_content_tab`
- *
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
* @example
- * fi.embed('label', 'name', {...options if needed})
+ * fi.tag('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {Array<'oembed'|'html'>} [fields.supported_source_types=all] `all` Array of source types that are supported by the field.
- * @param {Array<'photo'|'video'|'link'|'rich'>} [fields.supported_oembed_types=all] `all` Array of oEmbed types that are supported by the field.
- * @param {boolean} [fields.resizable=true] `true` Whether the embed is resizable
- * @param {boolean} [fields.show_preview=true] `true` Whether the embed is previewable
- * @param {Array} [fields.supported_media_bridge_providers] Array of provider IDs that determine which Media Bridge providers are available to select content from.
- * @param {Object} [fields.default] Default object --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|TAG_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
-function embed (label, name, fields) {
- const contentOptions = {}
- contentOptions.supported_source_types = fields?.supported_source_types ?? ['oembed', 'html']
- contentOptions.supported_oembed_types = fields?.supported_oembed_types ?? ['photo', 'video', 'link', 'rich']
- contentOptions.resizable = fields?.resizable ?? true
- contentOptions.show_preview = fields?.show_preview ?? true
- contentOptions.supported_media_bridge_providers = fields?.supported_media_bridge_providers ?? []
- const defaultObj = {
- source_type: 'oembed'
+function tag (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'tag' }
}
- contentOptions.default = { ...defaultObj, ...fields?.default }
+}
- const otherOptions = initField(label, name, 'embed', fields)
- return { ...contentOptions, ...otherOptions }
+/**
+ * #### videoplayer field
+ * `only_content_tab`
+ * @example
+ * fi.videoplayer('label', 'name', {...options if needed})
+ * @memberof Fields
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|VIDEO_FIELD} [fields]
+ * @returns {COMMON_FIELDS}
+ */
+function video (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'videoplayer' }
+ }
}
/**
- * #### CTA fields allow the user to select a call-to-action from the HubSpot CTA tool.
+ * #### url field
* `only_content_tab`
- *
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
* @example
- * fi.cta('label', 'name', {...options if needed})
+ * fi.url('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|URL_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
-function cta (label, name, fields) {
- const contentOptions = {}
- const otherOptions = initField(label, name, 'cta', fields)
- return { ...contentOptions, ...otherOptions }
+function url (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'url' }
+ }
}
-export { text, link, richtext, url, video, embed, cta }
+export {
+ text,
+ link,
+ richtext,
+ url,
+ video,
+ cta,
+ audioplayer,
+ blog,
+ crmobject,
+ crmobjectproperty,
+ date,
+ datetime,
+ email,
+ embed,
+ file,
+ form,
+ html,
+ hubdbrow,
+ hubdbtable,
+ hubl,
+ menu,
+ meeting,
+ logo,
+ simplemenu,
+ podcast,
+ payment,
+ page,
+ tag
+}
diff --git a/lib/fields.js b/lib/fields.js
index d9e6550..2f0abdb 100644
--- a/lib/fields.js
+++ b/lib/fields.js
@@ -1,265 +1,140 @@
-import * as TYPES from './types/types.js' // eslint-disable-line
-import { initField } from './utils/initField.js'
-
-/**
- * @ignore
- * @typedef {TYPES.EDITOR_OPTIONS} EDITOR_OPTIONS {@link EDITOR_OPTIONS}
- * @typedef {TYPES.DISPLAY_CONDITIONS} DISPLAY_CONDITIONS {@link DISPLAY_CONDITIONS}
- * @typedef {TYPES.REPEATER_OPTIONS} REPEATER_OPTIONS {@link REPEATER_OPTIONS}
- * @typedef {TYPES.REPEATER_OPTIONS_DEFAULT} REPEATER_OPTIONS_DEFAULT {@link REPEATER_OPTIONS_DEFAULT}
- * @typedef {TYPES.COMMON_FIELDS} COMMON_FIELDS {@link COMMON_FIELDS}
- */
-
+///
// *************
// General fields.
// Fields for content and style tab
// *************
/**
- * #### Number fields provide an easy interface for content creators to enter in or adjust numerical values and options. This can be used for creating percentage based items or anything where numbers are needed for input.
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
+ * #### Boolean field
* @example
- * fi.number('label', 'name', {...options if needed})
+ * fi.boolean('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {'slider'|'text'} [fields.display=text] `text` The display type for the number field.
- * @param {number} [fields.step=1] `1` The step value for the number field.
- * @param {number} [fields.min] Minimum value for the number field.
- * @param {number} [fields.max] Maximum value for the number field.
- * @param {string} [fields.prefix] Added as a prefix to the number field.
- * @param {string} [fields.suffix] Added as a suffix to the number field.
- * @param {string} [fields.placeholder] Adds a placeholder value to the field.
- * @param {?number} [fields.default] A default number to be used --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|BOOLEAN_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
-function number (label, name, fields) {
- const contentOptions = {}
- contentOptions.display = fields?.display ?? 'text'
- contentOptions.step = fields?.step ?? 1
- if (typeof fields !== 'undefined' && fields !== null && typeof fields === 'object') {
- if ('min' in fields) contentOptions.min = fields.min
- if ('max' in fields) contentOptions.max = fields.max
- if ('prefix' in fields) contentOptions.prefix = fields.prefix
- if ('suffix' in fields) contentOptions.suffix = fields.suffix
- if ('placeholder' in fields) contentOptions.placeholder = fields.placeholder
- if ('default' in fields) contentOptions.default = fields.default
+function boolean (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'boolean' }
}
-
- const otherOptions = initField(label, name, 'number', fields)
- return { ...contentOptions, ...otherOptions }
}
+
/**
- * #### This field provides a way for content editors to enable/disable functionality.
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
+ * #### Choice field
* @example
- * fi.boolean('label', 'name', {...options if needed})
+ * fi.choice('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {'toggle'|'checkbox'} [fields.display=checkbox] `checkbox` Choose the visual display style for the field. Can appear as either a toggle or a checkbox.
- * @param {boolean} [fields.default=false] `false` A default boolean value
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|CHOICE_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
-function boolean (label, name, fields) {
- const contentOptions = {}
- contentOptions.display = fields?.display ?? 'checkbox'
- contentOptions.default = fields?.default ?? false
-
- const otherOptions = initField(label, name, 'boolean', fields)
- return { ...contentOptions, ...otherOptions }
+function choice (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'choice' }
+ }
}
/**
- * #### Image fields provide an easy interface for content creators to add images to a module or theme.
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
+ * #### font field
* @example
- * fi.image('label', 'name', {...options if needed})
+ * fi.font('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {boolean} [fields.responsive=true] `true` Determines if the image is to act responsively or have a fixed height and width.
- * @param {boolean} [fields.show_loading=false] `false` Determines if the controls for choosing to lazy load the image are shown in the page editor.
- * @param {boolean} [fields.resizable=true] `true` Determines if the image is resizable in the page editor.
- * @param {Object} [fields.default] Default image properties --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {'auto'|'auto_custom_max'|'exact'} [fields.default.size_type=auto] `auto` Whether the image is automatically or manually sized. `auto`: HubSpot will automatically adjust the size of the image based on its original dimensions. `auto_custom_max`: HubSpot will automatically adjust the size of the image with maximum dimensions set using the `max_height` and `max_width` properties. `exact`: HubSpot will size the image based on the dimensions set using the `height` and `width` properties.
- * @param {string} [fields.default.src] The URL of the default image. Must be an absolute path to an image
- * @param {string} [fields.default.alt] The image's default alt-text.
- * @param {string} [fields.default.loading=lazy] `lazy` The image's lazy loading options
- * @param {number} [fields.default.width] The width of the image
- * @param {number} [fields.default.height] The height of the image
- * @param {number} [fields.default.max_width] The maximum width of the image
- * @param {number} [fields.default.max_height] The maximum height of the image
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|FONT_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
-function image (label, name, fields) {
- const contentOptions = {}
- contentOptions.responsive = fields?.responsive ?? true
- contentOptions.resizable = fields?.resizable ?? true
- contentOptions.show_loading = fields?.show_loading ?? false
- const defaultObj = {
- size_type: 'auto',
- src: '',
- alt: null,
- loading: 'lazy'
+function font (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'font' }
}
- contentOptions.default = fields?.default ?? defaultObj
-
- const otherOptions = initField(label, name, 'image', fields)
- return { ...contentOptions, ...otherOptions }
}
/**
- * #### Icon fields provide an icon picker UI to make it easier for content creators to add icons to your modules.
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
+ * #### Color field
* @example
- * fi.icon('label', 'name', {...options if needed})
+ * fi.color('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {'fontawesome-5.14.0'|'fontawesome-5.0.10'|'fontawesome-6.4.2'} [fields.icon_set='fontawesome-6.4.2'] `fontawesome-6.4.2` The FontAwesome icon set to use.
- * @param {Object} [fields.default] Defaout icon object --> It's generally a good idea to skip setting the `default` object, as it should be configured by the editor, not the developer
- * @param {string} [fields.default.name] The name of the icon
- * @param {string} [fields.default.unicode] The unicode of the icon
- * @param {'REGULAR'|'SOLID'} [fields.default.type] The type of the icon
- * @param {EDITOR_OPTIONS} [fields.editor_options] Editor options group.
- * @param {DISPLAY_CONDITIONS} [fields.display_conditions] Display conditions group.
- * @param {REPEATER_OPTIONS} [fields.repeater_options] Repeater options. Keep `occurrence` object empty to just enable a feature. `repeater_options: {occurrence: {}}`
- * @param {REPEATER_OPTIONS_DEFAULT} [fields.repeater_options_default] Repeater options with predefined repeated fields and `default` values for each field.
+ * @param {string} label Field label
+ * @param {string} name Field name (HubL variable name)
+ * @param {BASE_FIELDS|COLOR_FIELD} [fields]
* @returns {COMMON_FIELDS}
*/
-function icon (label, name, fields) {
- const contentOptions = {}
- contentOptions.icon_set = fields?.icon_set ?? 'fontawesome-6.4.2'
- contentOptions.default = fields?.default ?? {}
-
- const otherOptions = initField(label, name, 'icon', fields)
- return { ...contentOptions, ...otherOptions }
+function color (label, name, fields) {
+ return {
+ label,
+ name,
+ ...fields,
+ ...{ type: 'color' }
+ }
}
/**
- * #### Choice fields allow a content creator to select one or more items from a list of options, either within a dropdown menu, radio select, or checkboxes.
- * Some parameters have `default` values, `OMIT` such parameters if you don't want to override them.
+ * #### image field
* @example
- * fi.choice('label', 'name', {...options if needed})
+ * fi.image('label', 'name', {...options if needed})
* @memberof Fields
- * @param {string} label The text the content creator sees describing the field. May contain spaces.
- * @param {string} name Field/HubL variable name, which you'll reference when incorporating the field and its values in the module or theme. `Cannot contain spaces or special characters!`
- * @param {Object} [fields]
- * @param {boolean} [fields.multiple=false] `false` Optional. To allow multiple options to be selected, set the value to true.
- * @param {boolean} [fields.reordering_enabled=true] `true` Enables reordering of the choices in the editor.
- * @param {'select'|'radio'|'checkbox'} [fields.display=select] `select` Set the field's appearance. When not including multiple, you can set this as either `radio` or `select`. When multiple is set to true, you can set this as either `checkbox` or `select`.
- * @param {Array