@asymmetric-effort/specifyjs 0.3.7 → 1.0.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.
@@ -3089,11 +3089,16 @@ function Select(props) {
3089
3089
  disabled = false,
3090
3090
  error,
3091
3091
  label,
3092
- helpText
3092
+ helpText,
3093
+ creatable = false,
3094
+ onCreate,
3095
+ createLabel = "+ Create new..."
3093
3096
  } = props;
3094
3097
  const [isOpen, setIsOpen] = useState(false);
3095
3098
  const [searchQuery, setSearchQuery] = useState("");
3096
3099
  const [focusedIndex, setFocusedIndex] = useState(-1);
3100
+ const [isCreating, setIsCreating] = useState(false);
3101
+ const [createValue, setCreateValue] = useState("");
3097
3102
  const containerRef = useRef(null);
3098
3103
  const selectedValues = useMemo(
3099
3104
  () => Array.isArray(value) ? value : value ? [value] : [],
@@ -3128,6 +3133,8 @@ function Select(props) {
3128
3133
  if (containerRef.current && !containerRef.current.contains(target)) {
3129
3134
  setIsOpen(false);
3130
3135
  setSearchQuery("");
3136
+ setIsCreating(false);
3137
+ setCreateValue("");
3131
3138
  }
3132
3139
  };
3133
3140
  document.addEventListener("mousedown", handleClick);
@@ -3263,7 +3270,7 @@ function Select(props) {
3263
3270
  elements.push(renderOption(opt, flatIdx++));
3264
3271
  }
3265
3272
  }
3266
- if (elements.length === 0) {
3273
+ if (elements.length === 0 && !creatable) {
3267
3274
  elements.push(
3268
3275
  createElement(
3269
3276
  "div",
@@ -3272,6 +3279,82 @@ function Select(props) {
3272
3279
  )
3273
3280
  );
3274
3281
  }
3282
+ if (creatable) {
3283
+ if (isCreating) {
3284
+ elements.push(
3285
+ createElement(
3286
+ "div",
3287
+ {
3288
+ key: "__create-input__",
3289
+ style: {
3290
+ padding: "4px 8px",
3291
+ borderTop: elements.length > 0 ? "1px solid #e5e7eb" : "none"
3292
+ }
3293
+ },
3294
+ createElement("input", {
3295
+ type: "text",
3296
+ value: createValue,
3297
+ placeholder: "Type new value...",
3298
+ autoFocus: true,
3299
+ onInput: (e) => {
3300
+ setCreateValue(e.target.value);
3301
+ },
3302
+ onKeyDown: (e) => {
3303
+ const key = e.key;
3304
+ if (key === "Enter") {
3305
+ e.preventDefault();
3306
+ const trimmed = createValue.trim();
3307
+ if (trimmed) {
3308
+ if (onCreate) onCreate(trimmed);
3309
+ if (!multiple) {
3310
+ onChange(trimmed);
3311
+ setIsOpen(false);
3312
+ }
3313
+ setCreateValue("");
3314
+ setIsCreating(false);
3315
+ }
3316
+ } else if (key === "Escape") {
3317
+ setCreateValue("");
3318
+ setIsCreating(false);
3319
+ }
3320
+ },
3321
+ style: {
3322
+ width: "100%",
3323
+ boxSizing: "border-box",
3324
+ padding: "6px 8px",
3325
+ border: "1px solid #d1d5db",
3326
+ borderRadius: "4px",
3327
+ outline: "none",
3328
+ fontSize: "14px"
3329
+ }
3330
+ })
3331
+ )
3332
+ );
3333
+ } else {
3334
+ elements.push(
3335
+ createElement(
3336
+ "div",
3337
+ {
3338
+ key: "__create-new__",
3339
+ style: {
3340
+ padding: "8px 12px",
3341
+ cursor: "pointer",
3342
+ color: "#3b82f6",
3343
+ fontSize: "14px",
3344
+ borderTop: elements.length > 0 ? "1px solid #e5e7eb" : "none"
3345
+ },
3346
+ onClick: () => {
3347
+ setIsCreating(true);
3348
+ setCreateValue("");
3349
+ },
3350
+ role: "option",
3351
+ "aria-label": "Create new option"
3352
+ },
3353
+ createLabel
3354
+ )
3355
+ );
3356
+ }
3357
+ }
3275
3358
  return elements;
3276
3359
  };
3277
3360
  const chevron = createElement(
@@ -3672,6 +3755,12 @@ var BUTTON_META = {
3672
3755
  undo: { label: "Undo", icon: "\u21A9", command: "undo" },
3673
3756
  redo: { label: "Redo", icon: "\u21AA", command: "redo" }
3674
3757
  };
3758
+ var STRIP_SCRIPTS = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
3759
+ var STRIP_EVENTS_QUOTED = /\s+on\w+\s*=\s*(['"])[^'"]*\1/gi;
3760
+ var STRIP_EVENTS_UNQUOTED = /\s+on\w+\s*=\s*[^\s>]+/gi;
3761
+ function sanitizeRichText(html) {
3762
+ return html.replace(STRIP_SCRIPTS, "").replace(STRIP_EVENTS_QUOTED, "").replace(STRIP_EVENTS_UNQUOTED, "");
3763
+ }
3675
3764
  function TextEditor(props) {
3676
3765
  const [focused, setFocused] = useState(false);
3677
3766
  const editorRef = useRef(null);
@@ -3682,7 +3771,7 @@ function TextEditor(props) {
3682
3771
  const es = props.editorStyle ?? {};
3683
3772
  useEffect(() => {
3684
3773
  if (editorRef.current && props.value !== void 0) {
3685
- editorRef.current.innerHTML = props.value;
3774
+ editorRef.current.innerHTML = sanitizeRichText(props.value);
3686
3775
  }
3687
3776
  }, []);
3688
3777
  const execCommand = useCallback(
@@ -3691,6 +3780,7 @@ function TextEditor(props) {
3691
3780
  if (cmd === "createLink") {
3692
3781
  const url = prompt("Enter URL:");
3693
3782
  if (!url) return;
3783
+ if (/^(javascript|vbscript|data:text\/html)/i.test(url.trim())) return;
3694
3784
  document.execCommand(cmd, false, url);
3695
3785
  } else if (value && cmd === "formatBlock") {
3696
3786
  document.execCommand(cmd, false, `<${value}>`);