@cmstops/pro-compo 0.3.16 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { defineComponent, computed, openBlock, createElementBlock, createVNode, unref, withCtx, Fragment, renderList, createBlock, normalizeStyle, createCommentVNode } from "vue";
1
+ import { defineComponent, ref, computed, watch, openBlock, createElementBlock, createVNode, unref, withCtx, Fragment, renderList, createBlock, normalizeStyle, createCommentVNode } from "vue";
2
2
  import { RadioGroup, Radio } from "@arco-design/web-vue";
3
3
  import _sfc_main$1 from "./components/colorPicker.js";
4
4
  const _hoisted_1 = {
@@ -13,19 +13,12 @@ const _sfc_main = defineComponent({
13
13
  color: {},
14
14
  mode: {}
15
15
  },
16
- emits: ["change", "update:color"],
16
+ emits: ["update:color"],
17
17
  setup(__props, { emit: __emit }) {
18
18
  const props = __props;
19
19
  const emit = __emit;
20
20
  const _mode = props.mode || "rgb";
21
- const colorValue = computed({
22
- get() {
23
- return props.color;
24
- },
25
- set(value) {
26
- colorChange(value);
27
- }
28
- });
21
+ const colorValue = ref("");
29
22
  const colorRgb = (_color) => {
30
23
  if (_color.includes("rgb")) {
31
24
  return _color;
@@ -35,16 +28,35 @@ const _sfc_main = defineComponent({
35
28
  const blue = parseInt(_color.slice(5, 7), 16);
36
29
  return `rgb(${red},${green},${blue})`;
37
30
  };
31
+ const listValues = computed(() => {
32
+ if (_mode === "rgb") {
33
+ return props.colorList.map((color) => {
34
+ return colorRgb(color);
35
+ });
36
+ }
37
+ return props.colorList;
38
+ });
38
39
  const colorChange = (_color) => {
39
40
  if (_color) {
40
- if (_mode === "hex") {
41
- colorValue.value = _color;
42
- } else {
41
+ if (_mode === "rgb") {
43
42
  colorValue.value = colorRgb(_color.replace(/\s+/g, ""));
43
+ } else {
44
+ colorValue.value = _color;
44
45
  }
45
- emit("update:color", colorValue.value);
46
+ emit("update:color", JSON.parse(JSON.stringify(colorValue.value)));
46
47
  }
47
48
  };
49
+ watch(
50
+ () => props.color,
51
+ () => {
52
+ if (_mode === "rgb") {
53
+ colorValue.value = colorRgb(props.color);
54
+ } else {
55
+ colorValue.value = props.color;
56
+ }
57
+ },
58
+ { immediate: true }
59
+ );
48
60
  return (_ctx, _cache) => {
49
61
  return _ctx.colorList && _ctx.colorList.length ? (openBlock(), createElementBlock("div", _hoisted_1, [
50
62
  createVNode(unref(RadioGroup), {
@@ -55,7 +67,7 @@ const _sfc_main = defineComponent({
55
67
  onChange: colorChange
56
68
  }, {
57
69
  default: withCtx(() => [
58
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.colorList, (colr, index) => {
70
+ (openBlock(true), createElementBlock(Fragment, null, renderList(listValues.value, (colr, index) => {
59
71
  return openBlock(), createBlock(unref(Radio), {
60
72
  key: index,
61
73
  style: normalizeStyle({ background: `${colr} !important` }),
@@ -14,19 +14,12 @@ const _sfc_main = vue.defineComponent({
14
14
  color: {},
15
15
  mode: {}
16
16
  },
17
- emits: ["change", "update:color"],
17
+ emits: ["update:color"],
18
18
  setup(__props, { emit: __emit }) {
19
19
  const props = __props;
20
20
  const emit = __emit;
21
21
  const _mode = props.mode || "rgb";
22
- const colorValue = vue.computed({
23
- get() {
24
- return props.color;
25
- },
26
- set(value) {
27
- colorChange(value);
28
- }
29
- });
22
+ const colorValue = vue.ref("");
30
23
  const colorRgb = (_color) => {
31
24
  if (_color.includes("rgb")) {
32
25
  return _color;
@@ -36,16 +29,35 @@ const _sfc_main = vue.defineComponent({
36
29
  const blue = parseInt(_color.slice(5, 7), 16);
37
30
  return `rgb(${red},${green},${blue})`;
38
31
  };
32
+ const listValues = vue.computed(() => {
33
+ if (_mode === "rgb") {
34
+ return props.colorList.map((color) => {
35
+ return colorRgb(color);
36
+ });
37
+ }
38
+ return props.colorList;
39
+ });
39
40
  const colorChange = (_color) => {
40
41
  if (_color) {
41
- if (_mode === "hex") {
42
- colorValue.value = _color;
43
- } else {
42
+ if (_mode === "rgb") {
44
43
  colorValue.value = colorRgb(_color.replace(/\s+/g, ""));
44
+ } else {
45
+ colorValue.value = _color;
45
46
  }
46
- emit("update:color", colorValue.value);
47
+ emit("update:color", JSON.parse(JSON.stringify(colorValue.value)));
47
48
  }
48
49
  };
50
+ vue.watch(
51
+ () => props.color,
52
+ () => {
53
+ if (_mode === "rgb") {
54
+ colorValue.value = colorRgb(props.color);
55
+ } else {
56
+ colorValue.value = props.color;
57
+ }
58
+ },
59
+ { immediate: true }
60
+ );
49
61
  return (_ctx, _cache) => {
50
62
  return _ctx.colorList && _ctx.colorList.length ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
51
63
  vue.createVNode(vue.unref(webVue.RadioGroup), {
@@ -56,7 +68,7 @@ const _sfc_main = vue.defineComponent({
56
68
  onChange: colorChange
57
69
  }, {
58
70
  default: vue.withCtx(() => [
59
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.colorList, (colr, index) => {
71
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(listValues.value, (colr, index) => {
60
72
  return vue.openBlock(), vue.createBlock(vue.unref(webVue.Radio), {
61
73
  key: index,
62
74
  style: vue.normalizeStyle({ background: `${colr} !important` }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmstops/pro-compo",
3
- "version": "0.3.16",
3
+ "version": "0.3.17",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vue",