@pie-lib/mask-markup 0.1.0
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.
- package/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/choices/choice.d.ts +24 -0
- package/dist/choices/choice.d.ts.map +1 -0
- package/dist/choices/choice.js +77 -0
- package/dist/choices/index.d.ts +26 -0
- package/dist/choices/index.d.ts.map +1 -0
- package/dist/choices/index.js +49 -0
- package/dist/componentize.d.ts +13 -0
- package/dist/componentize.d.ts.map +1 -0
- package/dist/componentize.js +4 -0
- package/dist/components/blank.d.ts +39 -0
- package/dist/components/blank.d.ts.map +1 -0
- package/dist/components/blank.js +236 -0
- package/dist/components/correct-input.d.ts +11 -0
- package/dist/components/correct-input.d.ts.map +1 -0
- package/dist/components/dropdown.d.ts +38 -0
- package/dist/components/dropdown.d.ts.map +1 -0
- package/dist/components/dropdown.js +309 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/constructed-response.d.ts +24 -0
- package/dist/constructed-response.d.ts.map +1 -0
- package/dist/constructed-response.js +55 -0
- package/dist/customizable.d.ts +24 -0
- package/dist/customizable.d.ts.map +1 -0
- package/dist/customizable.js +8 -0
- package/dist/drag-in-the-blank.d.ts +38 -0
- package/dist/drag-in-the-blank.d.ts.map +1 -0
- package/dist/drag-in-the-blank.js +164 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/inline-dropdown.d.ts +24 -0
- package/dist/inline-dropdown.d.ts.map +1 -0
- package/dist/inline-dropdown.js +24 -0
- package/dist/mask.d.ts +31 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +98 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
- package/dist/serialization.d.ts +35 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/serialization.js +132 -0
- package/dist/with-mask.d.ts +35 -0
- package/dist/with-mask.d.ts.map +1 -0
- package/dist/with-mask.js +45 -0
- package/package.json +44 -0
- package/src/choices/choice.tsx +107 -0
- package/src/choices/index.tsx +74 -0
- package/src/componentize.tsx +23 -0
- package/src/components/blank.tsx +396 -0
- package/src/components/correct-input.tsx +92 -0
- package/src/components/dropdown.tsx +448 -0
- package/src/components/input.tsx +58 -0
- package/src/constructed-response.tsx +91 -0
- package/src/customizable.tsx +44 -0
- package/src/drag-in-the-blank.tsx +251 -0
- package/src/index.ts +26 -0
- package/src/inline-dropdown.tsx +39 -0
- package/src/mask.tsx +178 -0
- package/src/serialization.ts +270 -0
- package/src/with-mask.tsx +85 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { require_to_style as e } from "./node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js";
|
|
2
|
+
import t from "debug";
|
|
3
|
+
//#region src/serialization.ts
|
|
4
|
+
var n = e(), r = t("@pie-lib:mask-markup:serialization"), i = ["span"], a = [
|
|
5
|
+
"em",
|
|
6
|
+
"strong",
|
|
7
|
+
"u"
|
|
8
|
+
], o = 3, s = 8, c = 1, l = (e) => {
|
|
9
|
+
if (!e.attributes || e.attributes.length <= 0) return;
|
|
10
|
+
let t = {}, n;
|
|
11
|
+
for (n = 0; n < e.attributes.length; n++) {
|
|
12
|
+
let r = e.attributes[n];
|
|
13
|
+
t[r.name] = r.value;
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
}, u = (e) => i.includes(e) ? "inline" : a.includes(e) ? "mark" : "block", d = (e) => {
|
|
17
|
+
let t = /([\w-]*)\s*:\s*([^;]*)/g, n, r = {};
|
|
18
|
+
for (; n = t.exec(e);) r[n[1]] = n[2].trim();
|
|
19
|
+
return r;
|
|
20
|
+
}, f = (e) => (0, n.object)(e, {
|
|
21
|
+
camelize: !0,
|
|
22
|
+
addUnits: !1
|
|
23
|
+
}), p = (e, t) => f(d(e.getAttribute(t))), m = (e, t, n) => {
|
|
24
|
+
let r = e.getAttribute(n);
|
|
25
|
+
return delete t.class, r;
|
|
26
|
+
}, h = (e) => (t, n) => {
|
|
27
|
+
if (!e.getAttribute) return t;
|
|
28
|
+
if (e.getAttribute(n)) switch (n) {
|
|
29
|
+
case "style":
|
|
30
|
+
t.style = p(e, n);
|
|
31
|
+
break;
|
|
32
|
+
case "class":
|
|
33
|
+
t.className = m(e, t, n);
|
|
34
|
+
break;
|
|
35
|
+
default:
|
|
36
|
+
t[n] = e.getAttribute(n);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
}, g = [
|
|
41
|
+
"border",
|
|
42
|
+
"class",
|
|
43
|
+
"style"
|
|
44
|
+
], _ = {
|
|
45
|
+
b: "bold",
|
|
46
|
+
em: "italic",
|
|
47
|
+
u: "underline",
|
|
48
|
+
s: "strikethrough",
|
|
49
|
+
code: "code",
|
|
50
|
+
strong: "strong"
|
|
51
|
+
}, v = (e, t = []) => {
|
|
52
|
+
if (e.nodeType === s) return null;
|
|
53
|
+
if (e.nodeType === o) {
|
|
54
|
+
let n = { text: e.textContent };
|
|
55
|
+
return t.length > 0 && (n.marks = t.map((e) => ({
|
|
56
|
+
type: e,
|
|
57
|
+
data: void 0
|
|
58
|
+
}))), {
|
|
59
|
+
object: "text",
|
|
60
|
+
leaves: [n]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (e.nodeType === c) {
|
|
64
|
+
let n = e.tagName.toLowerCase(), i = _[n];
|
|
65
|
+
if (i) return r("[deserialize] mark: ", i), {
|
|
66
|
+
_flatten: !0,
|
|
67
|
+
nodes: y(e.childNodes, [...t, i])
|
|
68
|
+
};
|
|
69
|
+
if (n === "math") return {
|
|
70
|
+
isMath: !0,
|
|
71
|
+
nodes: [e]
|
|
72
|
+
};
|
|
73
|
+
let a = l(e) || {};
|
|
74
|
+
n === "audio" && a.controls === "" && (a.controls = !0);
|
|
75
|
+
let o = g.reduce(h(e), { ...a }), s = u(n), c = y(e.childNodes, t);
|
|
76
|
+
return {
|
|
77
|
+
object: s,
|
|
78
|
+
type: n,
|
|
79
|
+
data: {
|
|
80
|
+
dataset: { ...e.dataset },
|
|
81
|
+
attributes: { ...o }
|
|
82
|
+
},
|
|
83
|
+
nodes: c
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}, y = (e, t = []) => {
|
|
88
|
+
let n = [];
|
|
89
|
+
for (let r = 0; r < e.length; r++) {
|
|
90
|
+
let i = v(e[r], t);
|
|
91
|
+
i !== null && (i._flatten && i.nodes ? n.push(...i.nodes) : n.push(i));
|
|
92
|
+
}
|
|
93
|
+
return n;
|
|
94
|
+
}, b = (e) => {
|
|
95
|
+
if (!e || !e.trim()) return {
|
|
96
|
+
object: "value",
|
|
97
|
+
document: {
|
|
98
|
+
object: "document",
|
|
99
|
+
data: {},
|
|
100
|
+
nodes: [{
|
|
101
|
+
object: "block",
|
|
102
|
+
type: "span",
|
|
103
|
+
data: {},
|
|
104
|
+
isVoid: !1,
|
|
105
|
+
nodes: []
|
|
106
|
+
}]
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
let t = y(new DOMParser().parseFromString(e, "text/html").body.childNodes);
|
|
110
|
+
return !t.some((e) => e.object === "block" || e.object === "inline") && t.length > 0 && (t = [{
|
|
111
|
+
object: "block",
|
|
112
|
+
type: "span",
|
|
113
|
+
data: {},
|
|
114
|
+
isVoid: !1,
|
|
115
|
+
nodes: t
|
|
116
|
+
}]), t.length === 0 && (t = [{
|
|
117
|
+
object: "block",
|
|
118
|
+
type: "span",
|
|
119
|
+
data: {},
|
|
120
|
+
isVoid: !1,
|
|
121
|
+
nodes: []
|
|
122
|
+
}]), {
|
|
123
|
+
object: "value",
|
|
124
|
+
document: {
|
|
125
|
+
object: "document",
|
|
126
|
+
data: {},
|
|
127
|
+
nodes: t
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
//#endregion
|
|
132
|
+
export { _ as MARK_TAGS, b as deserialize };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/mask-markup/src/with-mask.jsx
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
import PropTypes from 'prop-types';
|
|
10
|
+
export declare const buildLayoutFromMarkup: (markup: any, type: any) => {
|
|
11
|
+
object: string;
|
|
12
|
+
data: {};
|
|
13
|
+
nodes: any;
|
|
14
|
+
};
|
|
15
|
+
export declare const withMask: (type: any, renderChildren: any) => {
|
|
16
|
+
new (props: any): {
|
|
17
|
+
componentDidUpdate(prevProps: any): void;
|
|
18
|
+
render(): JSX.Element;
|
|
19
|
+
};
|
|
20
|
+
propTypes: {
|
|
21
|
+
/**
|
|
22
|
+
* At the start we'll probably work with markup
|
|
23
|
+
*/
|
|
24
|
+
markup: PropTypes.Requireable<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.
|
|
27
|
+
*/
|
|
28
|
+
layout: PropTypes.Requireable<object>;
|
|
29
|
+
value: PropTypes.Requireable<object>;
|
|
30
|
+
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
31
|
+
customMarkMarkupComponent: PropTypes.Requireable<(...args: any[]) => any>;
|
|
32
|
+
elementType: PropTypes.Requireable<string>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=with-mask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-mask.d.ts","sourceRoot":"","sources":["../src/with-mask.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAGH,OAAO,SAAS,MAAM,YAAY,CAAC;AAKnC,eAAO,MAAM,qBAAqB,GAAI,WAAM,EAAE,SAAI;;;;CAIjD,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,SAAI,EAAE,mBAAc;;;;;;QAGvC;;WAEG;;QAEH;;WAEG;;;;;;;CAqDR,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { deserialize as e } from "./serialization.js";
|
|
2
|
+
import t from "./mask.js";
|
|
3
|
+
import n from "./componentize.js";
|
|
4
|
+
import r from "react";
|
|
5
|
+
import i from "prop-types";
|
|
6
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
7
|
+
//#region src/with-mask.tsx
|
|
8
|
+
var o = (t, r) => {
|
|
9
|
+
let { markup: i } = n(t, r);
|
|
10
|
+
return e(i).document;
|
|
11
|
+
}, s = (e, n) => class extends r.Component {
|
|
12
|
+
static propTypes = {
|
|
13
|
+
markup: i.string,
|
|
14
|
+
layout: i.object,
|
|
15
|
+
value: i.object,
|
|
16
|
+
onChange: i.func,
|
|
17
|
+
customMarkMarkupComponent: i.func,
|
|
18
|
+
elementType: i.string
|
|
19
|
+
};
|
|
20
|
+
constructor(e) {
|
|
21
|
+
super(e), this.containerRef = r.createRef();
|
|
22
|
+
}
|
|
23
|
+
componentDidUpdate(e) {
|
|
24
|
+
if (this.props.markup !== e.markup) {
|
|
25
|
+
let e = this.containerRef.current;
|
|
26
|
+
(e && e.querySelectorAll("[data-latex][data-math-handled=\"true\"]") || []).forEach((e) => {
|
|
27
|
+
let t = e.querySelector("mjx-container");
|
|
28
|
+
t && e.removeChild(t), e.innerHTML = e.getAttribute("data-raw"), e.removeAttribute("data-math-handled");
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
render() {
|
|
33
|
+
let { markup: r, layout: i, value: s, onChange: c, elementType: l } = this.props, u = i || o(r, e);
|
|
34
|
+
return /* @__PURE__ */ a(t, {
|
|
35
|
+
containerRef: this.containerRef,
|
|
36
|
+
elementType: l,
|
|
37
|
+
layout: u,
|
|
38
|
+
value: s,
|
|
39
|
+
onChange: c,
|
|
40
|
+
renderChildren: n(this.props)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { o as buildLayoutFromMarkup, s as withMask };
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-lib/mask-markup",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@emotion/react": "^11.14.0",
|
|
7
|
+
"@emotion/style": "^0.8.0",
|
|
8
|
+
"@mui/icons-material": "^7.3.4",
|
|
9
|
+
"@mui/material": "^7.3.4",
|
|
10
|
+
"@pie-lib/drag": "0.1.0",
|
|
11
|
+
"@pie-lib/editable-html-tip-tap": "0.1.0",
|
|
12
|
+
"@pie-lib/math-rendering": "0.1.0",
|
|
13
|
+
"@pie-lib/render-ui": "0.1.0",
|
|
14
|
+
"classnames": "^2.2.6",
|
|
15
|
+
"debug": "^4.1.1",
|
|
16
|
+
"lodash-es": "^4.17.23",
|
|
17
|
+
"prop-types": "^15.7.2",
|
|
18
|
+
"react": "^18.2.0",
|
|
19
|
+
"react-dom": "^18.2.0",
|
|
20
|
+
"to-style": "^1.3.3",
|
|
21
|
+
"@pie-element/shared-math-rendering-mathjax": "0.1.0",
|
|
22
|
+
"@dnd-kit/core": "6.3.1",
|
|
23
|
+
"@dnd-kit/utilities": "3.2.2"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"src"
|
|
37
|
+
],
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "bun x vite build && bun x tsc --emitDeclarationOnly",
|
|
41
|
+
"dev": "bun x vite",
|
|
42
|
+
"test": "bun x vitest run"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/mask-markup/src/choices/choice.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React, { useEffect, useRef } from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import { useDraggable } from '@dnd-kit/core';
|
|
14
|
+
import { styled } from '@mui/material/styles';
|
|
15
|
+
import Chip from '@mui/material/Chip';
|
|
16
|
+
import { renderMath } from '@pie-element/shared-math-rendering-mathjax';
|
|
17
|
+
import { color } from '@pie-lib/render-ui';
|
|
18
|
+
|
|
19
|
+
export const DRAG_TYPE = 'MaskBlank';
|
|
20
|
+
|
|
21
|
+
const StyledChoice: any = styled('span')(({ theme, disabled }) => ({
|
|
22
|
+
border: `solid 0px ${theme.palette.primary.main}`,
|
|
23
|
+
borderRadius: theme.spacing(2),
|
|
24
|
+
margin: theme.spacing(0.5),
|
|
25
|
+
transform: 'translate(0, 0)',
|
|
26
|
+
display: 'inline-flex',
|
|
27
|
+
...(disabled && {}),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const StyledChip: any = styled(Chip)(() => ({
|
|
31
|
+
backgroundColor: color.white(),
|
|
32
|
+
border: `1px solid ${color.text()}`,
|
|
33
|
+
color: color.text(),
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
display: 'inline-flex',
|
|
36
|
+
height: 'initial',
|
|
37
|
+
minHeight: '32px',
|
|
38
|
+
fontSize: 'inherit',
|
|
39
|
+
whiteSpace: 'pre-wrap',
|
|
40
|
+
maxWidth: '374px',
|
|
41
|
+
// Added for touch devices, for image content.
|
|
42
|
+
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
43
|
+
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
44
|
+
pointerEvents: 'none',
|
|
45
|
+
borderRadius: '3px',
|
|
46
|
+
paddingTop: '12px',
|
|
47
|
+
paddingBottom: '12px',
|
|
48
|
+
|
|
49
|
+
'&.Mui-disabled': {
|
|
50
|
+
opacity: 1,
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
const StyledChipLabel: any = styled('span')(() => ({
|
|
55
|
+
whiteSpace: 'normal',
|
|
56
|
+
'& img': {
|
|
57
|
+
display: 'block',
|
|
58
|
+
padding: '2px 0',
|
|
59
|
+
},
|
|
60
|
+
'& mjx-frac': {
|
|
61
|
+
fontSize: '120% !important',
|
|
62
|
+
},
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
export default function Choice({ choice, disabled, instanceId }) {
|
|
66
|
+
const rootRef = useRef(null);
|
|
67
|
+
|
|
68
|
+
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
69
|
+
id: `choice-${choice.id}`,
|
|
70
|
+
data: { choice, instanceId, fromChoice: true, type: DRAG_TYPE },
|
|
71
|
+
disabled,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
renderMath(rootRef.current);
|
|
76
|
+
}, [choice.value]);
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<StyledChoice
|
|
80
|
+
ref={setNodeRef}
|
|
81
|
+
style={
|
|
82
|
+
isDragging
|
|
83
|
+
? {
|
|
84
|
+
width: rootRef.current?.offsetWidth,
|
|
85
|
+
height: rootRef.current?.offsetHeight,
|
|
86
|
+
}
|
|
87
|
+
: {}
|
|
88
|
+
}
|
|
89
|
+
disabled={disabled}
|
|
90
|
+
{...listeners}
|
|
91
|
+
{...attributes}
|
|
92
|
+
>
|
|
93
|
+
<StyledChip
|
|
94
|
+
clickable={false}
|
|
95
|
+
disabled={disabled}
|
|
96
|
+
ref={rootRef}
|
|
97
|
+
label={<StyledChipLabel dangerouslySetInnerHTML={{ __html: choice.value }} />}
|
|
98
|
+
/>
|
|
99
|
+
</StyledChoice>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
Choice.propTypes = {
|
|
104
|
+
choice: PropTypes.object.isRequired,
|
|
105
|
+
disabled: PropTypes.bool,
|
|
106
|
+
instanceId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
107
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/mask-markup/src/choices/index.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import { findKey } from 'lodash-es';
|
|
14
|
+
import Choice from './choice.js';
|
|
15
|
+
import { DragDroppablePlaceholder } from '@pie-lib/drag';
|
|
16
|
+
|
|
17
|
+
export default class Choices extends React.Component {
|
|
18
|
+
static propTypes = {
|
|
19
|
+
disabled: PropTypes.bool,
|
|
20
|
+
duplicates: PropTypes.bool,
|
|
21
|
+
choices: PropTypes.arrayOf(PropTypes.shape({ label: PropTypes.string, value: PropTypes.string })),
|
|
22
|
+
value: PropTypes.object,
|
|
23
|
+
choicePosition: PropTypes.string.isRequired,
|
|
24
|
+
instanceId: PropTypes.string, // Added for drag isolation
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
getStyleForWrapper: any = () => {
|
|
28
|
+
const { choicePosition } = this.props;
|
|
29
|
+
|
|
30
|
+
switch (choicePosition) {
|
|
31
|
+
case 'above':
|
|
32
|
+
return {
|
|
33
|
+
margin: '0 0 40px 0',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
case 'below':
|
|
37
|
+
return {
|
|
38
|
+
margin: '40px 0 0 0',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
case 'right':
|
|
42
|
+
return {
|
|
43
|
+
margin: '0 0 0 40px',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
default:
|
|
47
|
+
return {
|
|
48
|
+
margin: '0 40px 0 0',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
render() {
|
|
54
|
+
const { disabled, duplicates, choices, value, instanceId } = this.props;
|
|
55
|
+
const filteredChoices = choices.filter((c) => {
|
|
56
|
+
if (duplicates === true) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
const foundChoice = findKey(value, (v) => v === c.id);
|
|
60
|
+
return foundChoice === undefined;
|
|
61
|
+
});
|
|
62
|
+
const elementStyle = { ...this.getStyleForWrapper(), minWidth: '100px' };
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div style={elementStyle}>
|
|
66
|
+
<DragDroppablePlaceholder disabled={disabled} instanceId={instanceId}>
|
|
67
|
+
{filteredChoices.map((c, index) => (
|
|
68
|
+
<Choice key={`${c.value}-${index}`} disabled={disabled} choice={c} instanceId={instanceId} />
|
|
69
|
+
))}
|
|
70
|
+
</DragDroppablePlaceholder>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/mask-markup/src/componentize.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const REGEX = /\{\{(\d+)\}\}/g;
|
|
12
|
+
|
|
13
|
+
export default (s, t) => {
|
|
14
|
+
if (!s) {
|
|
15
|
+
return { markup: '' };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const markup = s.replace(REGEX, (match, g) => {
|
|
19
|
+
return `<span data-component="${t}" data-id="${g}"></span>`;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return { markup };
|
|
23
|
+
};
|