This commit is contained in:
2025-08-25 20:24:23 +08:00
parent 30106e0129
commit 0ae8d7a709
1044 changed files with 321581 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [3.2.0](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.1.3...decap-cms-widget-colorstring@3.2.0) (2025-06-26)
**Note:** Version bump only for package decap-cms-widget-colorstring
## [3.1.3](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.1.2...decap-cms-widget-colorstring@3.1.3) (2024-08-13)
### Reverts
- Revert "Update dependencies (#7264)" ([22d483a](https://github.com/decaporg/decap-cms/commit/22d483a5b0c654071ae05735ac4f49abdc13d38c)), closes [#7264](https://github.com/decaporg/decap-cms/issues/7264)
## [3.1.2](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.1.1...decap-cms-widget-colorstring@3.1.2) (2024-08-13)
**Note:** Version bump only for package decap-cms-widget-colorstring
## [3.1.1](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.1.0-beta.2...decap-cms-widget-colorstring@3.1.1) (2024-03-21)
**Note:** Version bump only for package decap-cms-widget-colorstring
# [3.1.0](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.1.0-beta.2...decap-cms-widget-colorstring@3.1.0) (2024-02-01)
**Note:** Version bump only for package decap-cms-widget-colorstring
# [3.1.0-beta.2](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.1.0-beta.1...decap-cms-widget-colorstring@3.1.0-beta.2) (2024-01-31)
**Note:** Version bump only for package decap-cms-widget-colorstring
# [3.1.0-beta.1](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.1.0-beta.0...decap-cms-widget-colorstring@3.1.0-beta.1) (2024-01-16)
### Bug Fixes
- **#7007:** Replace validate color with tiny color 2 ([#7009](https://github.com/decaporg/decap-cms/issues/7009)) ([76b469c](https://github.com/decaporg/decap-cms/commit/76b469c754953a54dce60ac678eb3b4089850760)), closes [#7007](https://github.com/decaporg/decap-cms/issues/7007)
# [3.1.0-beta.0](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.1.0...decap-cms-widget-colorstring@3.1.0-beta.0) (2023-10-20)
### Reverts
- Revert "chore(release): publish" ([b89fc89](https://github.com/decaporg/decap-cms/commit/b89fc894dfbb5f4136b2e5427fd25a29378a58c6))
## [3.0.2](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.0.1...decap-cms-widget-colorstring@3.0.2) (2023-10-13)
**Note:** Version bump only for package decap-cms-widget-colorstring
## [3.0.1](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@3.0.0...decap-cms-widget-colorstring@3.0.1) (2023-08-25)
### Bug Fixes
- update peer dependencies ([#6886](https://github.com/decaporg/decap-cms/issues/6886)) ([e580ce5](https://github.com/decaporg/decap-cms/commit/e580ce52ce5f80fa040e8fbcab7fed0744f4f695))
# [3.0.0](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@1.2.0...decap-cms-widget-colorstring@3.0.0) (2023-08-18)
**Note:** Version bump only for package decap-cms-widget-colorstring
# [1.2.0](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@1.2.0-beta.0...decap-cms-widget-colorstring@1.2.0) (2023-08-18)
**Note:** Version bump only for package decap-cms-widget-colorstring
# 1.2.0-beta.0 (2023-08-18)
### Features
- rename packages ([#6863](https://github.com/decaporg/decap-cms/issues/6863)) ([d515e7b](https://github.com/decaporg/decap-cms/commit/d515e7bd33216a775d96887b08c4f7b1962941bb))
## [1.1.3-beta.0](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@1.1.2...decap-cms-widget-colorstring@1.1.3-beta.0) (2023-07-27)
**Note:** Version bump only for package decap-cms-widget-colorstring
## [1.1.2](https://github.com/decaporg/decap-cms/compare/decap-cms-widget-colorstring@1.1.1...decap-cms-widget-colorstring@1.1.2) (2022-03-08)
**Note:** Version bump only for package decap-cms-widget-colorstring
## [1.1.1](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring/compare/decap-cms-widget-colorstring@1.1.0...decap-cms-widget-colorstring@1.1.1) (2021-05-19)
**Note:** Version bump only for package decap-cms-widget-colorstring
# [1.1.0](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring/compare/decap-cms-widget-colorstring@1.0.3...decap-cms-widget-colorstring@1.1.0) (2021-05-04)
### Features
- added react 17 as peer dependency in packages ([#5316](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring/issues/5316)) ([9e42380](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring/commit/9e423805707321396eec137f5b732a5b07a0dd3f))
## [1.0.3](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring/compare/decap-cms-widget-colorstring@1.0.2...decap-cms-widget-colorstring@1.0.3) (2021-02-23)
**Note:** Version bump only for package decap-cms-widget-colorstring
## [1.0.2](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring/compare/decap-cms-widget-colorstring@1.0.1...decap-cms-widget-colorstring@1.0.2) (2021-02-10)
**Note:** Version bump only for package decap-cms-widget-colorstring
## 1.0.1 (2020-10-25)
### Bug Fixes
- **widget-color:** rename to colorstring ([#4496](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring/issues/4496)) ([fbc8963](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring/commit/fbc89637267f65ede25cd15ff6ed832ab3eb44dc))

View File

@@ -0,0 +1,9 @@
# Docs coming soon!
Decap CMS was converted from a single npm package to a "monorepo" of over 20 packages.
We haven't created a README for this package yet, but you can:
1. Check out the [main readme](https://github.com/decaporg/decap-cms/#readme) or the [documentation
site](https://www.decapcms.org) for more info.
2. Reach out to the [community chat](https://decapcms.org/chat/) if you need help.
3. Help out and [write the readme yourself](https://github.com/decaporg/decap-cms/edit/main/packages/decap-cms-widget-colorstring/README.md)!

View File

@@ -0,0 +1,33 @@
{
"name": "decap-cms-widget-colorstring",
"description": "Widget for editing color strings in Decap CMS.",
"version": "3.2.0",
"homepage": "https://www.decapcms.org/docs/widgets/#color",
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-colorstring",
"bugs": "https://github.com/decaporg/decap-cms/issues",
"module": "dist/esm/index.js",
"main": "dist/decap-cms-widget-colorstring.js",
"license": "MIT",
"keywords": [
"decap-cms",
"widget",
"color"
],
"sideEffects": false,
"scripts": {
"develop": "npm run build:esm -- --watch",
"build": "cross-env NODE_ENV=production webpack",
"build:esm": "cross-env NODE_ENV=esm babel src --out-dir dist/esm --ignore \"**/__tests__\" --root-mode upward"
},
"dependencies": {
"react-color": "^2.18.1",
"tinycolor2": "^1.4.1"
},
"peerDependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"decap-cms-ui-default": "^3.0.0",
"prop-types": "^15.7.2",
"react": "^19.1.0"
}
}

View File

@@ -0,0 +1,177 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import ChromePicker from 'react-color';
import tinycolor from 'tinycolor2';
import { zIndex } from 'decap-cms-ui-default';
function ClearIcon() {
return (
<svg height="20" width="20" viewBox="0 0 20 20" aria-hidden="true" focusable="false">
<path
fill="rgb(122, 130, 145)"
d="M14.348 14.849c-0.469 0.469-1.229 0.469-1.697 0l-2.651-3.030-2.651 3.029c-0.469 0.469-1.229 0.469-1.697 0-0.469-0.469-0.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-0.469-0.469-0.469-1.228 0-1.697s1.228-0.469 1.697 0l2.652 3.031 2.651-3.031c0.469-0.469 1.228-0.469 1.697 0s0.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c0.469 0.469 0.469 1.229 0 1.698z"
></path>
</svg>
);
}
const ClearButton = styled.div`
position: absolute;
right: 6px;
z-index: ${zIndex.zIndex1000};
padding: 8px;
margin-top: 11px;
`;
const ClearButtonWrapper = styled.div`
position: relative;
width: 100%;
`;
// color swatch background with checkerboard to display behind transparent colors
const ColorSwatchBackground = styled.div`
position: absolute;
z-index: ${zIndex.zIndex1};
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==');
height: 38px;
width: 48px;
margin-top: 10px;
margin-left: 10px;
border-radius: 5px;
`;
const ColorSwatch = styled.div`
position: absolute;
z-index: ${zIndex.zIndex2};
background: ${props => props.background};
cursor: pointer;
height: 38px;
width: 48px;
margin-top: 10px;
margin-left: 10px;
border-radius: 5px;
border: 2px solid rgb(223, 223, 227);
text-align: center;
font-size: 27px;
line-height: 1;
padding-top: 4px;
user-select: none;
color: ${props => props.color};
`;
const ColorPickerContainer = styled.div`
position: absolute;
z-index: ${zIndex.zIndex1000};
margin-top: 48px;
margin-left: 12px;
`;
// fullscreen div to close color picker when clicking outside of picker
const ClickOutsideDiv = styled.div`
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
`;
export default class ColorControl extends React.Component {
static propTypes = {
onChange: PropTypes.func.isRequired,
forID: PropTypes.string,
value: PropTypes.node,
classNameWrapper: PropTypes.string.isRequired,
setActiveStyle: PropTypes.func.isRequired,
setInactiveStyle: PropTypes.func.isRequired,
};
static defaultProps = {
value: '',
};
state = {
showColorPicker: false,
};
componentDidMount() {
// Manually validate PropTypes - React 19 breaking change
PropTypes.checkPropTypes(ColorControl.propTypes, this.props, 'prop', 'ColorControl');
}
// show/hide color picker
handleClick = () => {
this.setState({ showColorPicker: !this.state.showColorPicker });
};
handleClear = () => {
this.props.onChange('');
};
handleClose = () => {
this.setState({ showColorPicker: false });
};
handleChange = color => {
const formattedColor =
color.rgb.a < 1
? `rgba(${color.rgb.r}, ${color.rgb.g}, ${color.rgb.b}, ${color.rgb.a})`
: color.hex;
this.props.onChange(formattedColor);
};
render() {
const { forID, value, field, onChange, classNameWrapper, setActiveStyle, setInactiveStyle } =
this.props;
const allowInput = field.get('allowInput', false);
// clear button is not displayed if allowInput: true
const showClearButton = !allowInput && value;
return (
<>
{' '}
{showClearButton && (
<ClearButtonWrapper>
<ClearButton onClick={this.handleClear}>
<ClearIcon />
</ClearButton>
</ClearButtonWrapper>
)}
<ColorSwatchBackground />
<ColorSwatch
background={tinycolor(this.props.value).isValid() ? this.props.value : '#fff'}
color={
tinycolor(this.props.value).isValid() ? 'rgba(255, 255, 255, 0)' : 'rgb(223, 223, 227)'
}
onClick={this.handleClick}
>
?
</ColorSwatch>
{this.state.showColorPicker && (
<ColorPickerContainer>
<ClickOutsideDiv onClick={this.handleClose} />
<ChromePicker
color={value || ''}
onChange={this.handleChange}
disableAlpha={!field.get('enableAlpha', false)}
/>
</ColorPickerContainer>
)}
<input
// text input with padding left for the color swatch
type="text"
id={forID}
className={classNameWrapper}
value={value || ''}
onChange={e => onChange(e.target.value)}
onFocus={setActiveStyle}
onBlur={setInactiveStyle}
style={{
paddingLeft: '75px',
paddingRight: '70px',
color: !allowInput && '#bbb',
}}
// make readonly and open color picker on click if set to allowInput: false
onClick={!allowInput ? this.handleClick : undefined}
readOnly={!allowInput}
/>
</>
);
}
}

View File

@@ -0,0 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import { WidgetPreviewContainer } from 'decap-cms-ui-default';
function ColorPreview({ value }) {
return <WidgetPreviewContainer>{value}</WidgetPreviewContainer>;
}
ColorPreview.propTypes = {
value: PropTypes.node,
};
export default ColorPreview;

View File

@@ -0,0 +1,14 @@
import controlComponent from './ColorControl';
import previewComponent from './ColorPreview';
function Widget(opts = {}) {
return {
name: 'color',
controlComponent,
previewComponent,
...opts,
};
}
export const DecapCmsWidgetColorString = { Widget, controlComponent, previewComponent };
export default DecapCmsWidgetColorString;

View File

@@ -0,0 +1,3 @@
const { getConfig } = require('../../scripts/webpack.js');
module.exports = getConfig();