inline-style-editor 1.5.4 → 1.5.6

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/index.d.ts CHANGED
@@ -27,14 +27,16 @@ export interface SliderDefinition {
27
27
 
28
28
  export interface InlineStyleEditorOptions {
29
29
  onStyleChanged?: (
30
- target: HTMLElement,
30
+ target: HTMLElement | SVGElement,
31
31
  eventType: "inline" | CSSStyleRule,
32
32
  cssProp: string,
33
33
  value: string,
34
34
  ) => void;
35
- getElems: (el: HTMLElement) => void;
36
- customProps: Record<string, ColorDefinition | SelectDefinition | SliderDefinition>;
37
- cssRuleFilter: (el: HTMLElement, cssSelector: string) => boolean;
38
- getCssRuleName: (ruleName: string, el: HTMLElement) => string;
39
- inlineDeletable: (el: HTMLElement) => boolean,
35
+ getElems?: (el: HTMLElement | SVGElement) => [HTMLElement | SVGElement, string][];
36
+ listenOnClick?: boolean;
37
+ customProps?: Record<string, ColorDefinition | SelectDefinition | SliderDefinition>;
38
+ cssRuleFilter?: (el: HTMLElement | SVGElement, cssSelector: string) => boolean;
39
+ getCssRuleName?: (ruleName: string, el: HTMLElement | SVGElement) => string;
40
+ inlineDeletable?: (el: HTMLElement | SVGElement) => boolean;
41
+ ignoredProps?: string[];
40
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inline-style-editor",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "description": "Update CSS rules or add inline style to elements visualy",
5
5
  "scripts": {
6
6
  "build": "rollup --config",
@@ -42,7 +42,7 @@
42
42
  "stroke-width": {
43
43
  type: "slider",
44
44
  min: 0,
45
- max: 20,
45
+ max: 5,
46
46
  step: 0.5,
47
47
  suffix: "px",
48
48
  },
@@ -173,6 +173,10 @@
173
173
  const allProps = { ...cssPropByType, ...customProps };
174
174
  const _allCurrentPropDefs = pick(allProps, propByType[curType]);
175
175
  ignoredProps.forEach((prop) => delete _allCurrentPropDefs[prop]);
176
+ const elemTagName = currentElement?.tagName?.toLowerCase();
177
+ if (curType === typeText && (elemTagName === "text" || elemTagName === "tspan")) {
178
+ delete _allCurrentPropDefs["color"];
179
+ }
176
180
  Object.keys(_allCurrentPropDefs).forEach((key) => {
177
181
  const propSelectType = _allCurrentPropDefs[key].type;
178
182
  let retrieveType = "number";
@@ -199,7 +203,6 @@
199
203
  }
200
204
  }
201
205
  });
202
- console.log(_allCurrentPropDefs);
203
206
  const _propsByType = Object.entries(_allCurrentPropDefs)
204
207
  .reduce((byType, [propName, selectorDef]) => {
205
208
  const selectorType = selectorDef.type;
@@ -253,7 +256,10 @@
253
256
  const sheets = document.styleSheets;
254
257
  return elems.reduce((matchedRulesByElem, elemDef) => {
255
258
  const el = elemDef[0];
256
- const matchedRules = ["inline"];
259
+ const matchedRules = [];
260
+ if (cssRuleFilter === null || cssRuleFilter(el, "inline")) {
261
+ matchedRules.push("inline");
262
+ }
257
263
  for (let i in sheets) {
258
264
  try {
259
265
  const rules = sheets[i].cssRules;
@@ -342,6 +348,7 @@
342
348
  allTypes = getEditableTypes(targetsToSearch);
343
349
  hasDisplayedCustom = false;
344
350
  allRules = getMatchedCSSRules(targetsToSearch);
351
+ if (allRules.every((rules) => rules.length === 0)) return;
345
352
  for (let def of Object.values(customProps)) {
346
353
  if (def.getter(el) !== null) {
347
354
  hasDisplayedCustom = true;
@@ -583,11 +590,9 @@
583
590
  <div class="select-tab">
584
591
  <b> Applied to: </b>
585
592
  {#if nbChars(getRuleNamesTransformed(allRules[selectedElemIndex])) > 30}
586
- <select onchange={(e) => selectRule(e.target.value)}>
593
+ <select value={selectedRuleIndex} onchange={(e) => selectRule(e.target.value)}>
587
594
  {#each getRuleNames(allRules[selectedElemIndex]) as ruleName, ruleIndex}
588
- <option selected={selectedRuleIndex === ruleIndex} value={ruleIndex}
589
- >{getCssRuleName(ruleName, clickedElement)}</option
590
- >
595
+ <option value={ruleIndex}>{getCssRuleName(ruleName, clickedElement)}</option>
591
596
  {/each}
592
597
  </select>
593
598
  {:else}