Compare commits

..

No commits in common. "748af6a14f0e40b9c07052d10c7a25b396916d68" and "1f21469bce7b8b4d65c56610326e1cbf33f9eae3" have entirely different histories.

10 changed files with 580 additions and 2484 deletions

View File

@ -1,6 +1,3 @@
// Implements WordPress JS Coding Standards
// https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/
{ {
"root": true, "root": true,
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
@ -13,8 +10,7 @@
"extends": [ "extends": [
"plugin:react/recommended", "plugin:react/recommended",
"plugin:jsx-a11y/recommended", "plugin:jsx-a11y/recommended",
"plugin:jest/recommended", "plugin:jest/recommended"
"plugin:@typescript-eslint/recommended"
], ],
"env": { "env": {
"browser": false, "browser": false,
@ -146,15 +142,13 @@
"message": "Translate function arguments must be string literals." "message": "Translate function arguments must be string literals."
} }
], ],
"no-shadow": "off", "no-shadow": "error",
"@typescript-eslint/no-shadow": ["error"],
"no-undef": "error", "no-undef": "error",
"no-undef-init": "error", "no-undef-init": "error",
"no-unreachable": "error", "no-unreachable": "error",
"no-unsafe-negation": "error", "no-unsafe-negation": "error",
"no-unused-expressions": "error", "no-unused-expressions": "error",
"no-unused-vars": "off", "no-unused-vars": "error",
"@typescript-eslint/no-unused-vars": ["error"],
"no-useless-computed-key": "error", "no-useless-computed-key": "error",
"no-useless-constructor": "error", "no-useless-constructor": "error",
"no-useless-return": "error", "no-useless-return": "error",

View File

@ -4,7 +4,6 @@
"private": true, "private": true,
"main": "src/blocks.ts", "main": "src/blocks.ts",
"scripts": { "scripts": {
"lint:js": "wp-scripts lint-js 'src/**/*{.js,.jsx,.ts,.tsx}'",
"build:js": "webpack --mode=production", "build:js": "webpack --mode=production",
"build:sass": "sass src/styles:dist", "build:sass": "sass src/styles:dist",
"build": "npm run build:js && npm run build:sass", "build": "npm run build:js && npm run build:sass",

View File

@ -9,17 +9,17 @@ import { Spinner } from '@wordpress/components';
import { baseUrl } from '@/globals'; import { baseUrl } from '@/globals';
import { ReactComponent as CogIcon } from '@/assets/cogicon.svg'; import { ReactComponent as CogIcon } from '@/assets/cogicon.svg';
interface IPreviewProps { type PreviewProps = {
embedCode: string; embedCode: string;
} };
interface IPreviewState { type PreviewState = {
uniqueId: string; uniqueId: string;
loading: boolean; loading: boolean;
} };
class PreviewForm extends React.Component<IPreviewProps, IPreviewState> { class PreviewForm extends React.Component<PreviewProps, PreviewState> {
constructor( props: IPreviewProps ) { constructor( props: any ) {
super( props ); super( props );
// Generate a unique identifier, so that the embed script can be identified // Generate a unique identifier, so that the embed script can be identified
@ -39,7 +39,7 @@ class PreviewForm extends React.Component<IPreviewProps, IPreviewState> {
} }
// Force the embed script to load, which makes Iframes in the editor resize properly. // Force the embed script to load, which makes Iframes in the editor resize properly.
loadEmbedScript( callback?: () => void ) { loadEmbedScript( callback?: Function ) {
const existingScript = document.getElementById( `cog-embed-script-${ this.state.uniqueId }` ); const existingScript = document.getElementById( `cog-embed-script-${ this.state.uniqueId }` );
if ( ! existingScript ) { if ( ! existingScript ) {

View File

@ -5,14 +5,16 @@ import * as React from 'react';
import { Modal, FocusableIframe } from '@wordpress/components'; import { Modal, FocusableIframe } from '@wordpress/components';
import { baseUrl } from '@/globals'; import { baseUrl } from '@/globals';
import { IForm } from '@/types';
interface IDialogProps { interface IDialogProps {
setOpen: ( val: boolean ) => void; setOpen: Function;
onSelectForm: ( form: IForm ) => void; onSelectForm: Function;
} }
class SelectDialog extends React.Component<IDialogProps> { interface IDialogState {
}
class SelectDialog extends React.Component<IDialogProps, IDialogState> {
componentDidMount() { componentDidMount() {
window.addEventListener( 'message', this.handlePostMessage, false ); window.addEventListener( 'message', this.handlePostMessage, false );
} }

View File

@ -15,19 +15,18 @@ import { edit, external } from '@wordpress/icons';
import { useState } from '@wordpress/element'; import { useState } from '@wordpress/element';
import { BlockControls, InspectorControls } from '@wordpress/block-editor'; import { BlockControls, InspectorControls } from '@wordpress/block-editor';
import { IBlockAttributes, EmbedMode, IForm } from '@/types'; import { BlockAttributes, EmbedMode } from '@/types';
import { baseUrl } from './globals'; import { baseUrl } from './globals';
import { ReactComponent as CogIcon } from '@/assets/cogicon.svg'; import { ReactComponent as CogIcon } from '@/assets/cogicon.svg';
import SelectDialog from '@/components/select-dialog'; import SelectDialog from '@/components/select-dialog';
import PreviewForm from '@/components/preview-form'; import PreviewForm from '@/components/preview-form';
const Edit: React.FC<BlockEditProps<IBlockAttributes>> = ( { attributes, setAttributes, className } ) => { const Edit: React.FC<BlockEditProps<BlockAttributes>> = ( { attributes, setAttributes, className } ) => {
const [ selectDialogOpen, setSelectDialogOpen ] = useState( false ); const [ selectDialogOpen, setSelectDialogOpen ] = useState( false );
const handleForm = ( form: IForm ) => { const handleForm = ( form: { [key: string]: any } ) => {
setAttributes( { setAttributes( {
orgId: form.orgId,
formId: form.formId, formId: form.formId,
seamlessEmbedCode: form.embedCodes.Seamless, seamlessEmbedCode: form.embedCodes.Seamless,
iframeEmbedCode: form.embedCodes.IFrame, iframeEmbedCode: form.embedCodes.IFrame,

View File

@ -4,7 +4,7 @@
import { registerBlockType } from '@wordpress/blocks'; import { registerBlockType } from '@wordpress/blocks';
import { IBlockAttributes } from './types'; import { BlockAttributes } from './types';
/** /**
* Internal dependencies * Internal dependencies
@ -14,7 +14,7 @@ import Save from './save';
import { ReactComponent as CogIcon } from './assets/cogicon.svg'; import { ReactComponent as CogIcon } from './assets/cogicon.svg';
registerBlockType<IBlockAttributes>( 'cognito-forms/cognito-embed', { registerBlockType<BlockAttributes>( 'cognito-forms/cognito-embed', {
title: 'Cognito Forms', title: 'Cognito Forms',
icon: CogIcon, icon: CogIcon,
description: 'Easily build powerful forms.', description: 'Easily build powerful forms.',
@ -24,9 +24,6 @@ registerBlockType<IBlockAttributes>( 'cognito-forms/cognito-embed', {
html: false, html: false,
}, },
attributes: { attributes: {
orgId: {
type: 'string',
},
formId: { formId: {
type: 'string', type: 'string',
}, },

View File

@ -2,9 +2,9 @@ import * as React from 'react';
import { BlockSaveProps } from '@wordpress/blocks'; import { BlockSaveProps } from '@wordpress/blocks';
import { EmbedMode, IBlockAttributes } from './types'; import { EmbedMode, BlockAttributes } from './types';
const Save: React.FC<BlockSaveProps<IBlockAttributes>> = ( { attributes: { formId, embedMode, seamlessEmbedCode, iframeEmbedCode } } ) => { const Save: React.FC<BlockSaveProps<BlockAttributes>> = ( { attributes: { formId, embedMode, seamlessEmbedCode, iframeEmbedCode } } ) => {
let embedCode = ''; let embedCode = '';
switch ( embedMode ) { switch ( embedMode ) {

View File

@ -3,21 +3,10 @@ export enum EmbedMode {
IFrame, IFrame,
} }
export interface IBlockAttributes { export interface BlockAttributes {
orgId: string;
formId: string; formId: string;
iframeEmbedCode: string; iframeEmbedCode: string;
seamlessEmbedCode: string; seamlessEmbedCode: string;
ampEmbedCode: string; ampEmbedCode: string;
embedMode: EmbedMode; embedMode: EmbedMode;
} }
export interface IForm {
orgId: string;
formId: string;
embedCodes: {
Seamless: string;
IFrame: string;
Amp: string;
}
}

2996
yarn.lock

File diff suppressed because it is too large Load Diff