PluginProbe
WP Ultimate Post Grid / 4.1.1
WP Ultimate Post Grid v4.1.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / vendor / bv-settings / assets / js / admin / settings / setting / Code.js

Code.js in WP Ultimate Post Grid 4.1.1, at vendor/bv-settings/assets/js/admin/settings/setting/Code.js

83 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { Component } from 'react';
2 import CodeMirror from '@uiw/react-codemirror';
3 import * as events from '@uiw/codemirror-extensions-events';
4 import { css } from '@codemirror/lang-css';
5
6 export default class SettingCode extends Component {
7
8 constructor(props) {
9 super(props);
10
11 this.state = {
12 initialValue: props.value,
13 value: props.value,
14 indicatedChange: false,
15 };
16
17 this.onChange = this.onChange.bind(this);
18 this.updateParent = this.updateParent.bind(this);
19 }
20
21 shouldComponentUpdate(nextProps, nextState) {
22 return nextProps.value !== this.props.value
23 || nextState.value !== this.state.value
24 || nextState.indicatedChange !== this.state.indicatedChange
25 || nextState.initialValue !== this.state.initialValue;
26 }
27
28 componentDidUpdate(prevProps) {
29 if ( prevProps.value !== this.props.value && this.props.value !== this.state.value ) {
30 this.setState({
31 initialValue: this.props.value,
32 value: this.props.value,
33 indicatedChange: false,
34 });
35 }
36 }
37
38 onChange( value ) {
39 let newState = {
40 value: value,
41 };
42
43 let updateParent = false;
44 if ( value !== this.state.initialValue ) {
45 updateParent = true;
46 newState.indicatedChange = true;
47 } else {
48 if ( this.state.indicatedChange ) {
49 updateParent = true;
50 newState.indicatedChange = false;
51 }
52 }
53
54 this.setState( newState, () => {
55 if ( updateParent ) {
56 this.updateParent();
57 }
58 } );
59 }
60
61 updateParent() {
62 this.props.onValueChange( this.state.value );
63 }
64
65 render() {
66 return (
67 <CodeMirror
68 className="bvs-setting-input"
69 value={ this.state.value }
70 onChange={ this.onChange }
71 extensions={[
72 css(),
73 events.content({
74 blur: () => {
75 this.updateParent();
76 },
77 }),
78 ]}
79 />
80 );
81 }
82 }
83