@omegagrid/grid-core 0.10.2 → 0.10.5

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.
Files changed (201) hide show
  1. package/dist/__generated/functions.d.ts +4 -0
  2. package/dist/__generated/functions.d.ts.map +1 -0
  3. package/dist/__generated/functions.js +45 -0
  4. package/dist/__generated/functions.js.map +1 -0
  5. package/dist/calculations/autofill.d.ts +7 -0
  6. package/dist/calculations/autofill.d.ts.map +1 -0
  7. package/dist/calculations/autofill.js +84 -0
  8. package/dist/calculations/autofill.js.map +1 -0
  9. package/dist/calculations/conditions.d.ts +4 -0
  10. package/dist/calculations/conditions.d.ts.map +1 -0
  11. package/dist/calculations/conditions.js +41 -0
  12. package/dist/calculations/conditions.js.map +1 -0
  13. package/dist/calculations/context.d.ts +53 -0
  14. package/dist/calculations/context.d.ts.map +1 -0
  15. package/dist/calculations/context.js +85 -0
  16. package/dist/calculations/context.js.map +1 -0
  17. package/dist/calculations/formula.d.ts +89 -0
  18. package/dist/calculations/formula.d.ts.map +1 -0
  19. package/dist/calculations/formula.js +443 -0
  20. package/dist/calculations/formula.js.map +1 -0
  21. package/dist/calculations/functions/dates.d.ts +13 -0
  22. package/dist/calculations/functions/dates.d.ts.map +1 -0
  23. package/dist/calculations/functions/dates.js +58 -0
  24. package/dist/calculations/functions/dates.js.map +1 -0
  25. package/dist/calculations/functions/index.d.ts +11 -0
  26. package/dist/calculations/functions/index.d.ts.map +1 -0
  27. package/dist/calculations/functions/index.js +21 -0
  28. package/dist/calculations/functions/index.js.map +1 -0
  29. package/dist/calculations/functions/logical.d.ts +11 -0
  30. package/dist/calculations/functions/logical.d.ts.map +1 -0
  31. package/dist/calculations/functions/logical.js +50 -0
  32. package/dist/calculations/functions/logical.js.map +1 -0
  33. package/dist/calculations/functions/lookup.d.ts +18 -0
  34. package/dist/calculations/functions/lookup.d.ts.map +1 -0
  35. package/dist/calculations/functions/lookup.js +169 -0
  36. package/dist/calculations/functions/lookup.js.map +1 -0
  37. package/dist/calculations/functions/math.d.ts +72 -0
  38. package/dist/calculations/functions/math.d.ts.map +1 -0
  39. package/dist/calculations/functions/math.js +182 -0
  40. package/dist/calculations/functions/math.js.map +1 -0
  41. package/dist/calculations/functions/special.d.ts +2 -0
  42. package/dist/calculations/functions/special.d.ts.map +1 -0
  43. package/dist/calculations/functions/special.js +51 -0
  44. package/dist/calculations/functions/special.js.map +1 -0
  45. package/dist/calculations/functions/statistical.d.ts +7 -0
  46. package/dist/calculations/functions/statistical.d.ts.map +1 -0
  47. package/dist/calculations/functions/statistical.js +47 -0
  48. package/dist/calculations/functions/statistical.js.map +1 -0
  49. package/dist/calculations/functions/text.d.ts +29 -0
  50. package/dist/calculations/functions/text.d.ts.map +1 -0
  51. package/dist/calculations/functions/text.js +58 -0
  52. package/dist/calculations/functions/text.js.map +1 -0
  53. package/dist/calculations/helpers.d.ts +13 -0
  54. package/dist/calculations/helpers.d.ts.map +1 -0
  55. package/dist/calculations/helpers.js +32 -0
  56. package/dist/calculations/helpers.js.map +1 -0
  57. package/dist/calculations/index.d.ts +7 -0
  58. package/dist/calculations/index.d.ts.map +1 -0
  59. package/dist/calculations/index.js +7 -0
  60. package/dist/calculations/index.js.map +1 -0
  61. package/dist/calculations/operators.d.ts +19 -0
  62. package/dist/calculations/operators.d.ts.map +1 -0
  63. package/dist/calculations/operators.js +58 -0
  64. package/dist/calculations/operators.js.map +1 -0
  65. package/dist/calculations/tokenization.d.ts +36 -0
  66. package/dist/calculations/tokenization.d.ts.map +1 -0
  67. package/dist/calculations/tokenization.js +203 -0
  68. package/dist/calculations/tokenization.js.map +1 -0
  69. package/dist/common/index.d.ts +2 -0
  70. package/dist/common/index.d.ts.map +1 -0
  71. package/dist/common/index.js +2 -0
  72. package/dist/common/index.js.map +1 -0
  73. package/dist/common/range.d.ts +66 -0
  74. package/dist/common/range.d.ts.map +1 -0
  75. package/dist/common/range.js +222 -0
  76. package/dist/common/range.js.map +1 -0
  77. package/dist/constants.d.ts +68 -0
  78. package/dist/constants.d.ts.map +1 -0
  79. package/dist/constants.js +127 -0
  80. package/dist/constants.js.map +1 -0
  81. package/dist/index.d.ts +8 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/index.js +8 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/model/calculationModel.d.ts +30 -0
  86. package/dist/model/calculationModel.d.ts.map +1 -0
  87. package/dist/model/calculationModel.js +206 -0
  88. package/dist/model/calculationModel.js.map +1 -0
  89. package/dist/model/cellModel.d.ts +134 -0
  90. package/dist/model/cellModel.d.ts.map +1 -0
  91. package/dist/model/cellModel.js +371 -0
  92. package/dist/model/cellModel.js.map +1 -0
  93. package/dist/model/columnModel.d.ts +160 -0
  94. package/dist/model/columnModel.d.ts.map +1 -0
  95. package/dist/model/columnModel.js +159 -0
  96. package/dist/model/columnModel.js.map +1 -0
  97. package/dist/model/commentModel.d.ts +58 -0
  98. package/dist/model/commentModel.d.ts.map +1 -0
  99. package/dist/model/commentModel.js +81 -0
  100. package/dist/model/commentModel.js.map +1 -0
  101. package/dist/model/conditionalFormats.d.ts +104 -0
  102. package/dist/model/conditionalFormats.d.ts.map +1 -0
  103. package/dist/model/conditionalFormats.js +414 -0
  104. package/dist/model/conditionalFormats.js.map +1 -0
  105. package/dist/model/cssStyle.d.ts +20 -0
  106. package/dist/model/cssStyle.d.ts.map +1 -0
  107. package/dist/model/cssStyle.js +301 -0
  108. package/dist/model/cssStyle.js.map +1 -0
  109. package/dist/model/dependencies.d.ts +30 -0
  110. package/dist/model/dependencies.d.ts.map +1 -0
  111. package/dist/model/dependencies.js +139 -0
  112. package/dist/model/dependencies.js.map +1 -0
  113. package/dist/model/dependencyModel.d.ts +9 -0
  114. package/dist/model/dependencyModel.d.ts.map +1 -0
  115. package/dist/model/dependencyModel.js +9 -0
  116. package/dist/model/dependencyModel.js.map +1 -0
  117. package/dist/model/elementModel.d.ts +103 -0
  118. package/dist/model/elementModel.d.ts.map +1 -0
  119. package/dist/model/elementModel.js +181 -0
  120. package/dist/model/elementModel.js.map +1 -0
  121. package/dist/model/filterModel.d.ts +35 -0
  122. package/dist/model/filterModel.d.ts.map +1 -0
  123. package/dist/model/filterModel.js +153 -0
  124. package/dist/model/filterModel.js.map +1 -0
  125. package/dist/model/gridModel.d.ts +181 -0
  126. package/dist/model/gridModel.d.ts.map +1 -0
  127. package/dist/model/gridModel.js +797 -0
  128. package/dist/model/gridModel.js.map +1 -0
  129. package/dist/model/groupModel.d.ts +26 -0
  130. package/dist/model/groupModel.d.ts.map +1 -0
  131. package/dist/model/groupModel.js +112 -0
  132. package/dist/model/groupModel.js.map +1 -0
  133. package/dist/model/history.d.ts +24 -0
  134. package/dist/model/history.d.ts.map +1 -0
  135. package/dist/model/history.js +35 -0
  136. package/dist/model/history.js.map +1 -0
  137. package/dist/model/index.d.ts +23 -0
  138. package/dist/model/index.d.ts.map +1 -0
  139. package/dist/model/index.js +23 -0
  140. package/dist/model/index.js.map +1 -0
  141. package/dist/model/iterableRange.d.ts +49 -0
  142. package/dist/model/iterableRange.d.ts.map +1 -0
  143. package/dist/model/iterableRange.js +108 -0
  144. package/dist/model/iterableRange.js.map +1 -0
  145. package/dist/model/merges.d.ts +34 -0
  146. package/dist/model/merges.d.ts.map +1 -0
  147. package/dist/model/merges.js +123 -0
  148. package/dist/model/merges.js.map +1 -0
  149. package/dist/model/namingModel.d.ts +25 -0
  150. package/dist/model/namingModel.d.ts.map +1 -0
  151. package/dist/model/namingModel.js +77 -0
  152. package/dist/model/namingModel.js.map +1 -0
  153. package/dist/model/options.d.ts +257 -0
  154. package/dist/model/options.d.ts.map +1 -0
  155. package/dist/model/options.js +35 -0
  156. package/dist/model/options.js.map +1 -0
  157. package/dist/model/rowModel.d.ts +104 -0
  158. package/dist/model/rowModel.d.ts.map +1 -0
  159. package/dist/model/rowModel.js +155 -0
  160. package/dist/model/rowModel.js.map +1 -0
  161. package/dist/model/selectionModel.d.ts +19 -0
  162. package/dist/model/selectionModel.d.ts.map +1 -0
  163. package/dist/model/selectionModel.js +40 -0
  164. package/dist/model/selectionModel.js.map +1 -0
  165. package/dist/model/sortingModel.d.ts +46 -0
  166. package/dist/model/sortingModel.d.ts.map +1 -0
  167. package/dist/model/sortingModel.js +157 -0
  168. package/dist/model/sortingModel.js.map +1 -0
  169. package/dist/model/style.d.ts +90 -0
  170. package/dist/model/style.d.ts.map +1 -0
  171. package/dist/model/style.js +34 -0
  172. package/dist/model/style.js.map +1 -0
  173. package/dist/model/styleModel.d.ts +22 -0
  174. package/dist/model/styleModel.d.ts.map +1 -0
  175. package/dist/model/styleModel.js +91 -0
  176. package/dist/model/styleModel.js.map +1 -0
  177. package/dist/model/tableTheme.d.ts +46 -0
  178. package/dist/model/tableTheme.d.ts.map +1 -0
  179. package/dist/model/tableTheme.js +93 -0
  180. package/dist/model/tableTheme.js.map +1 -0
  181. package/dist/model/validations.d.ts +5 -0
  182. package/dist/model/validations.d.ts.map +1 -0
  183. package/dist/model/validations.js +24 -0
  184. package/dist/model/validations.js.map +1 -0
  185. package/dist/sparklines/index.d.ts +2 -0
  186. package/dist/sparklines/index.d.ts.map +1 -0
  187. package/dist/sparklines/index.js +2 -0
  188. package/dist/sparklines/index.js.map +1 -0
  189. package/dist/sparklines/sparklines.d.ts +59 -0
  190. package/dist/sparklines/sparklines.d.ts.map +1 -0
  191. package/dist/sparklines/sparklines.js +176 -0
  192. package/dist/sparklines/sparklines.js.map +1 -0
  193. package/dist/types.d.ts +103 -0
  194. package/dist/types.d.ts.map +1 -0
  195. package/dist/types.js +2 -0
  196. package/dist/types.js.map +1 -0
  197. package/dist/utils.d.ts +4 -0
  198. package/dist/utils.d.ts.map +1 -0
  199. package/dist/utils.js +11 -0
  200. package/dist/utils.js.map +1 -0
  201. package/package.json +3 -3
@@ -0,0 +1,90 @@
1
+ import { IconSpec } from '@omegagrid/core';
2
+ import { CSSStyle } from './cssStyle';
3
+ export type HorizontalAlignment = 'left' | 'right' | 'center';
4
+ export type VerticalAlignment = 'top' | 'bottom' | 'center';
5
+ export interface Alignment {
6
+ /** Indent level */
7
+ indent?: number;
8
+ /** Wrap text */
9
+ wrapText?: boolean;
10
+ /** Horizontal Alignment */
11
+ horizontal?: HorizontalAlignment;
12
+ /** Vertical Alignment */
13
+ vertical?: VerticalAlignment;
14
+ /** Text rotation */
15
+ textRotation?: number;
16
+ }
17
+ export type Color = string;
18
+ export type BorderStyle = 'none' | 'thin' | 'medium' | 'thick' | 'double' | 'dotted' | 'hair' | 'dashed' | 'mediumDashed' | 'dashDot' | 'mediumDashDot' | 'dashDotDot' | 'mediumDashDotDot' | 'slantDashDot';
19
+ export type PatternStyle = 'solid' | 'darkGray' | 'mediumGray' | 'lightGray' | 'gray125' | 'gray0625' | 'darkHorizontal' | 'darkVertical' | 'darkDown' | 'darkUp' | 'darkGrid' | 'darkTrellis' | 'lightHorizontal' | 'lightVertical' | 'lightDown' | 'lightUp' | 'lightGrid' | 'lightTrellis';
20
+ export interface Border {
21
+ /** Border Style */
22
+ style?: BorderStyle;
23
+ /** Border Color */
24
+ color?: Color;
25
+ }
26
+ export interface CellBorderStyle {
27
+ top?: Border;
28
+ right?: Border;
29
+ bottom?: Border;
30
+ left?: Border;
31
+ }
32
+ export interface TextStyle {
33
+ /** Bold text style */
34
+ bold?: boolean;
35
+ /** Italic text style */
36
+ italic?: boolean;
37
+ /** Underline text style */
38
+ underline?: boolean;
39
+ /** Font Size */
40
+ sz?: number;
41
+ /** Strike-through text style */
42
+ strike?: boolean;
43
+ /** Font Name */
44
+ font?: string;
45
+ /** Text Color */
46
+ color?: Color;
47
+ }
48
+ export type GradientStop = {
49
+ v: number;
50
+ rgb: Color;
51
+ };
52
+ export interface Style extends TextStyle {
53
+ /** Top Border */
54
+ top?: Border;
55
+ /** Bottom Border */
56
+ bottom?: Border;
57
+ /** Left Border */
58
+ left?: Border;
59
+ /** Right Border */
60
+ right?: Border;
61
+ /** Pattern Type (optional) */
62
+ patternType?: PatternStyle;
63
+ /** Cell Primary (background) Color */
64
+ fgColor?: Color;
65
+ /** Cell Secondary (background) Color */
66
+ bgColor?: Color;
67
+ /** Cell alignment properties */
68
+ alignment?: Alignment;
69
+ /** Cell background gradient angle */
70
+ angle?: number;
71
+ /** Cell background gradient segments */
72
+ stops?: GradientStop[];
73
+ /** Cell formula hidden when worksheet is locked */
74
+ hidden?: boolean;
75
+ /** Cell editable when worksheet is locked (inverse of "locked" in Excel) */
76
+ editable?: boolean;
77
+ /** cell icon */
78
+ icon?: IconSpec;
79
+ cssStyle?: CSSStyle;
80
+ /** Style Name */
81
+ style?: string;
82
+ hash?: string;
83
+ id?: number;
84
+ [name: string]: unknown;
85
+ }
86
+ export type StylePropertyKey = keyof Style;
87
+ export declare const borderToString: (b?: Border) => string;
88
+ export declare const alignmentToString: (a?: Alignment) => string;
89
+ export declare const hashStyle: (s: Style) => string;
90
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../src/model/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAC9D,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5D,MAAM,WAAW,SAAS;IACtB,mBAAmB;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gBAAgB;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,mBAAmB,CAAC;IAEjC,yBAAyB;IACzB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAE7B,oBAAoB;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC;A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3
+ const convertString = (value) => value == null ? '_' : value;
4
+ const convertNumber = (value) => value == null ? '_' : value.toString();
5
+ const convertObject = (value) => value == null ? '_' : JSON.stringify(value);
6
+ export const borderToString = (b) => convertString(b && b.color ? b.color : '_') + convertString(b && b.style ? b.style : '_');
7
+ export const alignmentToString = (a) => convertString(a ? a.horizontal : null)
8
+ + convertString(a ? a.vertical : null)
9
+ + convertString(a ? a.horizontal : null)
10
+ + convertNumber(a ? a.indent : null)
11
+ + convertBool(a ? a.wrapText : null)
12
+ + convertNumber(a ? a.textRotation : null);
13
+ export const hashStyle = (s) => sha1('s_'
14
+ + convertBool(s.bold)
15
+ + convertBool(s.italic)
16
+ + convertBool(s.underline)
17
+ + convertNumber(s.sz)
18
+ + convertString(s.font)
19
+ + convertString(s.color)
20
+ + borderToString(s.top)
21
+ + borderToString(s.right)
22
+ + borderToString(s.bottom)
23
+ + borderToString(s.left)
24
+ + convertString(s.patternType)
25
+ + convertString(s.fgColor)
26
+ + convertString(s.bgColor)
27
+ + alignmentToString(s.alignment)
28
+ + convertNumber(s.angle)
29
+ + convertObject(s.stops)
30
+ + convertBool(s.hidden)
31
+ + convertBool(s.editable)
32
+ + convertObject(s.cssStyle)
33
+ + convertObject(s.icon));
34
+ //# sourceMappingURL=style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.js","sourceRoot":"","sources":["../../src/model/style.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AA0IxB,MAAM,WAAW,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAC1D,MAAM,aAAa,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AACrE,MAAM,aAAa,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,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AAC,CAAC,CAAC,IAAI,CAAC;MACnB,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC;MACrB,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;MACxB,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;MACnB,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;MACrB,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;MACtB,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC;MACrB,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC;MACvB,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC;MACxB,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC;MACtB,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC;MAC5B,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC;MACxB,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC;MACxB,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC;MAC3B,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;MACzB,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;MACtB,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC;MACrB,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC;MACpB,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC;MACzB,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAC1B,CAAC","sourcesContent":["import { IconSpec } from '@omegagrid/core';\nimport { CSSStyle } from './cssStyle';\nimport sha1 from 'sha1';\n\nexport type HorizontalAlignment = 'left' | 'right' | 'center';\nexport type VerticalAlignment = 'top' | 'bottom' | 'center';\n\nexport interface Alignment {\n /** Indent level */\n indent?: number;\n\n /** Wrap text */\n wrapText?: boolean;\n\n /** Horizontal Alignment */\n horizontal?: HorizontalAlignment;\n\n /** Vertical Alignment */\n vertical?: VerticalAlignment;\n\n /** Text rotation */\n textRotation?: number;\n}\n\nexport type Color = string;\n\nexport type BorderStyle = 'none' | 'thin' | 'medium' | 'thick' | 'double' | 'dotted' | 'hair' | 'dashed' | 'mediumDashed' | 'dashDot' | 'mediumDashDot' | 'dashDotDot' | 'mediumDashDotDot' | 'slantDashDot';\n\nexport type PatternStyle = \n\t'solid'\t\t\t\t// Solid\n\t|'darkGray'\t\t\t// 75% Gray\n\t|'mediumGray'\t\t// 50% Gray\n\t|'lightGray'\t\t// 25% Gray\n\t|'gray125'\t\t\t// 12.5% Gray\n\t|'gray0625'\t\t\t// 6.25% Gray\n\t|'darkHorizontal'\t// Horizontal Stripe\n\t|'darkVertical'\t\t// Vertical Stripe\n\t|'darkDown'\t\t\t// Reverse Diagonal Stripe\n\t|'darkUp'\t\t\t// Diagonal Stripe\n\t|'darkGrid'\t\t\t// Diagonal Crosshatch\n\t|'darkTrellis'\t\t// Thick Diagonal Crosshatch\n\t|'lightHorizontal'\t// Thin Horizontal Stripe\n\t|'lightVertical'\t// Thin Vertical Stripe\n\t|'lightDown'\t\t// Thin Reverse Diagonal Stripe\n\t|'lightUp'\t\t\t// Thin Diagonal Stripe\n\t|'lightGrid'\t\t// Thin Horizontal Crosshatch\n\t|'lightTrellis'\t\t// Thin Diagonal Crosshatch\n\nexport interface Border {\n /** Border Style */\n style?: BorderStyle;\n /** Border Color */\n color?: Color;\n}\n\nexport interface CellBorderStyle {\n top?: Border;\n right?: Border;\n bottom?: Border;\n left?: Border;\n}\n\nexport interface TextStyle {\n /** Bold text style */\n bold?: boolean;\n\n /** Italic text style */\n italic?: boolean;\n\n /** Underline text style */\n underline?: boolean;\n\n /** Font Size */\n sz?: number;\n\n /** Strike-through text style */\n strike?: boolean;\n\n /** Font Name */\n font?: string;\n\n /** Text Color */\n color?: Color;\n}\n\nexport type GradientStop = {v: number, rgb: Color};\n\nexport interface Style extends TextStyle {\n /** Top Border */\n top?: Border;\n\n /** Bottom Border */\n bottom?: Border;\n\n /** Left Border */\n left?: Border;\n\n /** Right Border */\n right?: Border;\n\n /** Pattern Type (optional) */\n patternType?: PatternStyle;\n\n /** Cell Primary (background) Color */\n fgColor?: Color;\n\n /** Cell Secondary (background) Color */\n bgColor?: Color;\n\n /** Cell alignment properties */\n alignment?: Alignment;\n\n /** Cell background gradient angle */\n angle?: number,\n\n /** Cell background gradient segments */\n stops?: GradientStop[]\n\n /** Cell formula hidden when worksheet is locked */\n hidden?: boolean;\n\n /** Cell editable when worksheet is locked (inverse of \"locked\" in Excel) */\n editable?: boolean;\n\n /** cell icon */\n icon?: IconSpec;\n\n\tcssStyle?: CSSStyle;\n\n /** Style Name */\n style?: string;\n\n\thash?: string;\n\tid?: number;\n\n\t[name: string]: unknown;\n}\n\nexport type StylePropertyKey = keyof Style;\n\nconst convertBool = (value: boolean) => value ? '1' : '0';\nconst convertString = (value: string) => value == null ? '_' : value;\nconst convertNumber = (value: number) => value == null ? '_' : value.toString();\nconst convertObject = (value: object) => value == null ? '_' : JSON.stringify(value);\n\nexport const borderToString = (b?: Border) => convertString(b && b.color ? b.color : '_') + convertString(b && b.style ? b.style : '_');\nexport const alignmentToString = (a?: Alignment) => convertString(a ? a.horizontal : null)\n\t+ convertString(a ? a.vertical : null)\n\t+ convertString(a ? a.horizontal : null)\n\t+ convertNumber(a ? a.indent : null)\n\t+ convertBool(a ? a.wrapText : null)\n\t+ convertNumber(a ? a.textRotation : null)\n\nexport const hashStyle = (s: Style) => sha1('s_'\n\t+ convertBool(s.bold)\n\t+ convertBool(s.italic)\n\t+ convertBool(s.underline)\n\t+ convertNumber(s.sz)\n\t+ convertString(s.font)\n\t+ convertString(s.color)\n\t+ borderToString(s.top)\n\t+ borderToString(s.right)\n\t+ borderToString(s.bottom)\n\t+ borderToString(s.left)\n\t+ convertString(s.patternType)\n\t+ convertString(s.fgColor)\n\t+ convertString(s.bgColor)\n\t+ alignmentToString(s.alignment)\n + convertNumber(s.angle)\n\t+ convertObject(s.stops)\n\t+ convertBool(s.hidden)\n\t+ convertBool(s.editable)\n + convertObject(s.cssStyle)\n + convertObject(s.icon)\n);\n"]}
@@ -0,0 +1,22 @@
1
+ import { CSSStyle } from "./cssStyle";
2
+ import { GridModel } from "./gridModel";
3
+ import { Style, StylePropertyKey } from "./style";
4
+ import { StyleSource } from "../types";
5
+ export declare class StyleModel {
6
+ readonly model: GridModel;
7
+ private _count;
8
+ private hashmap;
9
+ readonly map: Map<number, Style>;
10
+ constructor(model: GridModel);
11
+ add(styleSource: StyleSource): Style;
12
+ populate(styles: (string | CSSStyle | Style)[]): void;
13
+ get(id: number): Style;
14
+ remove(style: number | Style): void;
15
+ merge(...s: (number | Style)[]): Style;
16
+ duplicate(id: number, props: Record<StylePropertyKey, unknown>): Style;
17
+ set(id: number, props: Record<StylePropertyKey, unknown>): Style;
18
+ unset(id: number, props: string[]): void;
19
+ getSourceData(): Style[];
20
+ clean(): void;
21
+ }
22
+ //# sourceMappingURL=styleModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styleModel.d.ts","sourceRoot":"","sources":["../../src/model/styleModel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAmB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAa,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AASvC,qBAAa,UAAU;IAMV,QAAQ,CAAC,KAAK,EAAE,SAAS;IAJrC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,OAAO,CAA6B;IAC5C,SAAgB,GAAG,qBAA4B;gBAE1B,KAAK,EAAE,SAAS;IAErC,GAAG,CAAC,WAAW,EAAE,WAAW;IAa5B,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,GAAC,QAAQ,GAAC,KAAK,CAAC,EAAE;IAI1C,GAAG,CAAC,EAAE,EAAE,MAAM;IAId,MAAM,CAAC,KAAK,EAAE,MAAM,GAAC,KAAK;IAM1B,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,GAAC,KAAK,CAAC,EAAE,GAAG,KAAK;IAKpC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG,KAAK;IAKtE,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG,KAAK;IAOhE,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAOjC,aAAa;IAIb,KAAK;CAqBL"}
@@ -0,0 +1,91 @@
1
+ import { utils } from "@omegagrid/core";
2
+ import { cssStyleToStyle } from "./cssStyle";
3
+ import { hashStyle } from "./style";
4
+ function removeId(style) {
5
+ const s = { ...style };
6
+ delete s.id;
7
+ delete s.hash;
8
+ return s;
9
+ }
10
+ export class StyleModel {
11
+ constructor(model) {
12
+ this.model = model;
13
+ this._count = 0;
14
+ this.hashmap = new Map();
15
+ this.map = new Map();
16
+ }
17
+ add(styleSource) {
18
+ if (!isNaN(styleSource))
19
+ return this.get(styleSource);
20
+ const style = this.model.options.cssStyles ? cssStyleToStyle(styleSource) : styleSource;
21
+ const hash = style.hash ? style.hash : hashStyle(style);
22
+ if (this.hashmap.has(hash))
23
+ return this.map.get(this.hashmap.get(hash));
24
+ if (style.id == null)
25
+ style.id = this._count;
26
+ this._count = Math.max(style.id + 1, this._count + 1);
27
+ style.hash = hash;
28
+ this.hashmap.set(hash, style.id);
29
+ this.map.set(style.id, style);
30
+ return style;
31
+ }
32
+ populate(styles) {
33
+ styles.forEach(style => this.add(style));
34
+ }
35
+ get(id) {
36
+ return this.map.has(id) ? this.map.get(id) : null;
37
+ }
38
+ remove(style) {
39
+ const s = typeof style == 'object' ? style : this.map.get(style);
40
+ this.hashmap.delete(s.hash);
41
+ this.map.delete(s.id);
42
+ }
43
+ merge(...s) {
44
+ const style = Object.assign({}, ...(s.map(id => utils.isObject(id) ? id : this.get(id))));
45
+ return this.add(removeId(style));
46
+ }
47
+ duplicate(id, props) {
48
+ const origStyle = this.get(id);
49
+ return this.add(removeId({ ...origStyle, ...props }));
50
+ }
51
+ set(id, props) {
52
+ let style = this.map.has(id) ? this.map.get(id) : {};
53
+ for (const k in props)
54
+ style[k] = props[k];
55
+ style = style.id ? style : this.add(style);
56
+ return style;
57
+ }
58
+ unset(id, props) {
59
+ if (this.map.has(id)) {
60
+ const style = this.map.get(id);
61
+ for (const k of props)
62
+ delete style[k];
63
+ }
64
+ }
65
+ getSourceData() {
66
+ return Array.from(this.map.values());
67
+ }
68
+ clean() {
69
+ const styleIds = new Map(Array.from(this.map.entries()).map(([id]) => [id, 0]));
70
+ this.model.columns.forEach(column => {
71
+ const num = styleIds.get(column.style);
72
+ if (num != null)
73
+ styleIds.set(column.style, num + 1);
74
+ });
75
+ this.model.rows.forEach(row => {
76
+ const num = styleIds.get(row.style);
77
+ if (num != null)
78
+ styleIds.set(row.style, num + 1);
79
+ row.cells.forEach(cell => {
80
+ const num = styleIds.get(cell.style);
81
+ if (num != null)
82
+ styleIds.set(cell.style, num + 1);
83
+ });
84
+ });
85
+ styleIds.forEach((cnt, id) => {
86
+ if (cnt == 0)
87
+ this.remove(id);
88
+ });
89
+ }
90
+ }
91
+ //# sourceMappingURL=styleModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styleModel.js","sourceRoot":"","sources":["../../src/model/styleModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAY,eAAe,EAAE,MAAM,YAAY,CAAC;AAEvD,OAAO,EAA2B,SAAS,EAAE,MAAM,SAAS,CAAC;AAG7D,SAAS,QAAQ,CAAC,KAAY;IAC7B,MAAM,CAAC,GAAG,EAAC,GAAG,KAAK,EAAC,CAAC;IACrB,OAAO,CAAC,CAAC,EAAE,CAAC;IACZ,OAAO,CAAC,CAAC,IAAI,CAAC;IACd,OAAO,CAAC,CAAC;AACV,CAAC;A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Q,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvC,IAAI,GAAG,IAAI,IAAI;gBAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAC7B,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,GAAG,IAAI,IAAI;gBAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;YAClD,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACxB,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACrC,IAAI,GAAG,IAAI,IAAI;oBAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;YAC5B,IAAI,GAAG,IAAI,CAAC;gBAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACJ,CAAC;CAED","sourcesContent":["import { utils } from \"@omegagrid/core\";\nimport { CSSStyle, cssStyleToStyle } from \"./cssStyle\";\nimport { GridModel } from \"./gridModel\";\nimport { Style, StylePropertyKey, hashStyle } from \"./style\";\nimport { StyleSource } from \"../types\";\n\nfunction removeId(style: Style) {\n\tconst s = {...style};\n\tdelete s.id;\n\tdelete s.hash;\n\treturn s;\n}\n\nexport class StyleModel {\n\n\tprivate _count = 0;\n\tprivate hashmap = new Map<string, number>();\n\tpublic readonly map = new Map<number, Style>();\n\n\tconstructor(readonly model: GridModel) {}\n\n\tadd(styleSource: StyleSource) {\n\t\tif (!isNaN(styleSource as number)) return this.get(styleSource as number);\n\t\tconst style = this.model.options.cssStyles ? cssStyleToStyle(styleSource as string|CSSStyle) : (styleSource as Style);\n\t\tconst hash = style.hash ? style.hash : hashStyle(style);\n\t\tif (this.hashmap.has(hash)) return this.map.get(this.hashmap.get(hash));\n\t\tif (style.id == null) style.id = this._count;\n\t\tthis._count = Math.max(style.id + 1, this._count + 1);\n\t\tstyle.hash = hash;\n\t\tthis.hashmap.set(hash, style.id);\n\t\tthis.map.set(style.id, style);\n\t\treturn style;\n\t}\n\n\tpopulate(styles: (string|CSSStyle|Style)[]) {\n\t\tstyles.forEach(style => this.add(style));\n\t}\n\n\tget(id: number) {\n\t\treturn this.map.has(id) ? this.map.get(id) : null;\n\t}\n\n\tremove(style: number|Style) {\n\t\tconst s = typeof style == 'object' ? style : this.map.get(style);\n\t\tthis.hashmap.delete(s.hash);\n\t\tthis.map.delete(s.id);\n\t}\n\n\tmerge(...s: (number|Style)[]): Style {\n\t\tconst style = Object.assign({}, ...(s.map(id => utils.isObject(id) ? id : this.get(id as number))));\n\t\treturn this.add(removeId(style));\n\t}\n\n\tduplicate(id: number, props: Record<StylePropertyKey, unknown>): Style {\n\t\tconst origStyle = this.get(id);\n\t\treturn this.add(removeId({...origStyle, ...props}));\n\t}\n\n\tset(id: number, props: Record<StylePropertyKey, unknown>): Style {\n\t\tlet style = this.map.has(id) ? this.map.get(id) : {};\n\t\tfor (const k in props) style[k] = props[k];\n\t\tstyle = style.id ? style : this.add(style);\n\t\treturn style;\n\t}\n\n\tunset(id: number, props: string[]) {\n\t\tif (this.map.has(id)) {\n\t\t\tconst style = this.map.get(id);\n\t\t\tfor (const k of props) delete style[k];\n\t\t}\n\t}\n\n\tgetSourceData() {\n\t\treturn Array.from(this.map.values());\n\t}\n\n\tclean() {\n\t\tconst styleIds = new Map<number, number>(Array.from(this.map.entries()).map(([id]) => [id, 0]));\n\t\tthis.model.columns.forEach(column => {\n\t\t\tconst num = styleIds.get(column.style);\n\t\t\tif (num != null) styleIds.set(column.style, num + 1);\n\t\t});\n\n\t\tthis.model.rows.forEach(row => {\n\t\t\tconst num = styleIds.get(row.style);\n\t\t\tif (num != null) styleIds.set(row.style, num + 1);\n\t\t\trow.cells.forEach(cell => {\n\t\t\t\tconst num = styleIds.get(cell.style);\n\t\t\t\tif (num != null) styleIds.set(cell.style, num + 1);\n\t\t\t});\n\t\t});\n\n\t\tstyleIds.forEach((cnt, id) => {\n\t\t\tif (cnt == 0) this.remove(id);\n\t\t});\n\t}\n\n}"]}
@@ -0,0 +1,46 @@
1
+ import { GridModel } from "./gridModel";
2
+ import { RowModel } from "./rowModel";
3
+ import { ColumnModel } from "./columnModel";
4
+ import { ConditionalFormatItemSource } from "./conditionalFormats";
5
+ import { CellModel } from "./cellModel";
6
+ import { CellRange } from "../common";
7
+ export type ThemeItemCondtion = {
8
+ property?: keyof CellModel;
9
+ value?: unknown;
10
+ };
11
+ export type ThemeItem = Omit<ConditionalFormatItemSource, 'ranges'> & {
12
+ conditions?: ThemeItemCondtion[];
13
+ };
14
+ export type ThemeAxisItem = ThemeItem & {
15
+ /** style will apply on cells with specific row/column index */
16
+ index?: number;
17
+ /** style will apply on cells with specific row/column level */
18
+ level?: number;
19
+ /** style will apply on cells their names are matching regular expression */
20
+ name?: string | RegExp;
21
+ /** axis property priority */
22
+ priority?: number;
23
+ };
24
+ export type ThemeRowItem = ThemeAxisItem & {
25
+ /** row height */
26
+ height?: number;
27
+ };
28
+ export type ThemeColumnItem = ThemeAxisItem & {
29
+ /** column width */
30
+ width?: number;
31
+ };
32
+ export type TableTheme = {
33
+ /** theme name */
34
+ name: string;
35
+ /** styles for cells */
36
+ cells?: ThemeItem[];
37
+ /** styles for columns */
38
+ columns?: ThemeColumnItem[];
39
+ /** styles for rows */
40
+ rows?: ThemeRowItem[];
41
+ };
42
+ export declare function applyCellTheme(theme: TableTheme, model: GridModel, range?: CellRange): void;
43
+ export declare function applyColumnTheme(theme: TableTheme, model: GridModel, columns?: ColumnModel[]): void;
44
+ export declare function applyRowTheme(theme: TableTheme, model: GridModel, rows?: RowModel[]): void;
45
+ export declare function applyTheme(theme: TableTheme, model: GridModel): void;
46
+ //# sourceMappingURL=tableTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableTheme.d.ts","sourceRoot":"","sources":["../../src/model/tableTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAC,GAAG;IACrE,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACvC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,GAAC,MAAM,CAAC;IACrB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG;IAC1C,iBAAiB;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAC7C,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACxB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,yBAAyB;IACzB,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,sBAAsB;IACtB,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC;CACtB,CAAA;AA0DD,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,SAAS,QAsBpF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,QAE5F;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,QAEnF;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,QAI7D"}
@@ -0,0 +1,93 @@
1
+ import { utils } from "@omegagrid/core";
2
+ function getLevelMap(nodes) {
3
+ const map = new Map();
4
+ for (const node of nodes) {
5
+ if (!map.has(node.level))
6
+ map.set(node.level, []);
7
+ map.get(node.level).push(node);
8
+ }
9
+ return map;
10
+ }
11
+ function applyAxisTheme(theme, model, type, tableElements) {
12
+ const nodes = tableElements ?? (type == 'rows' ? model.rows : model.columns);
13
+ const levelMap = getLevelMap(nodes);
14
+ const themeItems = theme[type] ?? [];
15
+ for (const item of themeItems) {
16
+ let effectiveNodes;
17
+ if (item.index > -1) {
18
+ effectiveNodes = [nodes[item.index]];
19
+ }
20
+ else if (item.level > -1) {
21
+ effectiveNodes = levelMap.get(item.level);
22
+ }
23
+ else {
24
+ effectiveNodes = nodes;
25
+ }
26
+ if (item.name) {
27
+ const nameRegExp = item.name instanceof RegExp ? item.name : new RegExp(utils.escapeRegExp(item.name));
28
+ effectiveNodes = effectiveNodes.filter(node => nameRegExp.test(node.name));
29
+ }
30
+ effectiveNodes?.forEach(node => {
31
+ if (item.priority != null)
32
+ node.priority = item.priority;
33
+ if (item.type) { // conditional format
34
+ model.conditionalFormats.add(Object.assign({
35
+ ranges: `${node.address}:${node.address}`
36
+ }, item));
37
+ }
38
+ else { // static format
39
+ node.style = model.styles.add(item.style).id;
40
+ if (type == 'rows' && item.height != null) {
41
+ node.height = item.height;
42
+ }
43
+ else if (type == 'columns' && item.width != null) {
44
+ node.width = item.width;
45
+ }
46
+ }
47
+ });
48
+ }
49
+ }
50
+ function matchConditions(conditions, cell) {
51
+ for (const condition of conditions) {
52
+ if (cell[condition.property] != condition.value)
53
+ return false;
54
+ }
55
+ return true;
56
+ }
57
+ export function applyCellTheme(theme, model, range) {
58
+ const themeItems = theme.cells ?? [];
59
+ for (const item of themeItems) {
60
+ if (item.conditions?.length) {
61
+ const iterator = model.getRangeIterator(range ?? model.gridRange);
62
+ for (const cell of iterator) {
63
+ if (matchConditions(item.conditions, cell)) {
64
+ cell.style = model.styles.add(item.style).id;
65
+ }
66
+ }
67
+ }
68
+ else if (item.type) { // conditional format
69
+ model.conditionalFormats.add(Object.assign({
70
+ ranges: 'A:' + model.columns[model.columns.length - 1].address
71
+ }, item));
72
+ }
73
+ else { // static format
74
+ for (const column of model.columns) {
75
+ if (column.style != null)
76
+ continue;
77
+ column.style = model.styles.add(item.style).id;
78
+ }
79
+ }
80
+ }
81
+ }
82
+ export function applyColumnTheme(theme, model, columns) {
83
+ applyAxisTheme(theme, model, 'columns', columns);
84
+ }
85
+ export function applyRowTheme(theme, model, rows) {
86
+ applyAxisTheme(theme, model, 'rows', rows);
87
+ }
88
+ export function applyTheme(theme, model) {
89
+ applyCellTheme(theme, model);
90
+ applyColumnTheme(theme, model);
91
+ applyRowTheme(theme, model);
92
+ }
93
+ //# sourceMappingURL=tableTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableTheme.js","sourceRoot":"","sources":["../../src/model/tableTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAiD9C,SAAS,WAAW,CAA8B,KAAU;IAC3D,MAAM,GAAG,GAAG,IAAI,GAAG,EAAe,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,SAAS,cAAc,CAAC,KAAiB,EAAE,KAAgB,EAAE,IAAsB,EAAE,aAAwC;IAC5H,MAAM,KAAK,GAAG,aAAa,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7E,MAAM,QAAQ,GAAG,WAAW,CAAuB,KAAK,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC/B,IAAI,cAAwC,CAAC;QAC7C,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;YACrB,cAAc,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACtC,CAAC;aAAM,IAAI,IAAI,CAAC,K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OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO;aAC9D,EAAE,IAAI,CAAC,CAAC,CAAC;QACX,CAAC;aAAM,CAAC,CAAC,gBAAgB;YACxB,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;gBACpC,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI;oBAAE,SAAS;gBACnC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAChD,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAiB,EAAE,KAAgB,EAAE,OAAuB;IAC5F,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAiB,EAAE,KAAgB,EAAE,IAAiB;IACnF,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,KAAgB;IAC7D,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7B,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC/B,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { tree, utils } from \"@omegagrid/core\";\nimport { GridModel } from \"./gridModel\";\nimport { RowModel } from \"./rowModel\";\nimport { ColumnModel } from \"./columnModel\";\nimport { ConditionalFormatItemSource } from \"./conditionalFormats\";\nimport { CellModel } from \"./cellModel\";\nimport { CellRange } from \"../common\";\n\nexport type ThemeItemCondtion = {\n\tproperty?: keyof CellModel;\n\tvalue?: unknown;\n}\n\nexport type ThemeItem = Omit<ConditionalFormatItemSource, 'ranges'> & {\n\tconditions?: ThemeItemCondtion[]\n};\n\nexport type ThemeAxisItem = ThemeItem & {\n\t/** style will apply on cells with specific row/column index */\n\tindex?: number;\n\t/** style will apply on cells with specific row/column level */\n\tlevel?: number;\n\t/** style will apply on cells their names are matching regular expression */\n\tname?: string|RegExp;\n\t/** axis property priority */\n\tpriority?: number;\n}\n\nexport type ThemeRowItem = ThemeAxisItem & {\n\t/** row height */\n\theight?: number;\n}\n\nexport type ThemeColumnItem = ThemeAxisItem & {\n\t/** column width */\n\twidth?: number;\n}\n\nexport type TableTheme = {\n\t/** theme name */\n\tname: string;\n\t/** styles for cells */\n\tcells?: ThemeItem[],\n\t/** styles for columns */\n\tcolumns?: ThemeColumnItem[],\n\t/** styles for rows */\n\trows?: ThemeRowItem[],\n}\n\nfunction getLevelMap<T extends tree.TreeNodeType>(nodes: T[]) {\n\tconst map = new Map<number, T[]>();\n\tfor (const node of nodes) {\n\t\tif (!map.has(node.level)) map.set(node.level, []);\n\t\tmap.get(node.level).push(node);\n\t}\n\treturn map;\n}\n\nfunction applyAxisTheme(theme: TableTheme, model: GridModel, type: 'rows'|'columns', tableElements?: (RowModel|ColumnModel)[]) {\n\tconst nodes = tableElements ?? (type == 'rows' ? model.rows : model.columns);\n\tconst levelMap = getLevelMap<RowModel|ColumnModel>(nodes);\n\tconst themeItems = theme[type] ?? [];\n\n\tfor (const item of themeItems) {\n\t\tlet effectiveNodes: (RowModel|ColumnModel)[];\n\t\tif (item.index > -1) {\n\t\t\teffectiveNodes = [nodes[item.index]];\n\t\t} else if (item.level > -1) {\n\t\t\teffectiveNodes = levelMap.get(item.level);\n\t\t} else {\n\t\t\teffectiveNodes = nodes;\n\t\t}\n\n\t\tif (item.name) {\n\t\t\tconst nameRegExp = item.name instanceof RegExp ? item.name : new RegExp(utils.escapeRegExp(item.name));\n\t\t\teffectiveNodes = effectiveNodes.filter(node => nameRegExp.test(node.name));\n\t\t}\n\n\t\teffectiveNodes?.forEach(node => {\n\t\t\tif (item.priority != null) node.priority = item.priority;\n\n\t\t\tif (item.type) { // conditional format\n\t\t\t\tmodel.conditionalFormats.add(Object.assign({\n\t\t\t\t\tranges: `${node.address}:${node.address}`\n\t\t\t\t}, item));\n\t\t\t} else { // static format\n\t\t\t\tnode.style = model.styles.add(item.style).id;\n\n\t\t\t\tif (type == 'rows' && (item as ThemeRowItem).height != null) {\n\t\t\t\t\t(node as RowModel).height = (item as ThemeRowItem).height;\n\t\t\t\t} else if (type == 'columns' && (item as ThemeColumnItem).width != null) {\n\t\t\t\t\t(node as ColumnModel).width = (item as ThemeColumnItem).width;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n}\n\nfunction matchConditions(conditions: ThemeItemCondtion[], cell: CellModel) {\n\tfor (const condition of conditions) {\n\t\tif (cell[condition.property] != condition.value) return false;\n\t}\n\treturn true;\n}\n\nexport function applyCellTheme(theme: TableTheme, model: GridModel, range?: CellRange) {\n\tconst themeItems = theme.cells ?? [];\n\n\tfor (const item of themeItems) {\n\t\tif (item.conditions?.length) {\n\t\t\tconst iterator = model.getRangeIterator(range ?? model.gridRange);\n\t\t\tfor (const cell of iterator) {\n\t\t\t\tif (matchConditions(item.conditions, cell)) {\n\t\t\t\t\tcell.style = model.styles.add(item.style).id;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (item.type) { // conditional format\n\t\t\tmodel.conditionalFormats.add(Object.assign({\n\t\t\t\tranges: 'A:' + model.columns[model.columns.length - 1].address\n\t\t\t}, item));\n\t\t} else { // static format\n\t\t\tfor (const column of model.columns) {\n\t\t\t\tif (column.style != null) continue;\n\t\t\t\tcolumn.style = model.styles.add(item.style).id;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function applyColumnTheme(theme: TableTheme, model: GridModel, columns?: ColumnModel[]) {\n\tapplyAxisTheme(theme, model, 'columns', columns);\n}\n\nexport function applyRowTheme(theme: TableTheme, model: GridModel, rows?: RowModel[]) {\n\tapplyAxisTheme(theme, model, 'rows', rows);\n}\n\nexport function applyTheme(theme: TableTheme, model: GridModel) {\n\tapplyCellTheme(theme, model);\n\tapplyColumnTheme(theme, model);\n\tapplyRowTheme(theme, model);\n}"]}
@@ -0,0 +1,5 @@
1
+ import { CellValidation, CellValidationSource } from "../types";
2
+ import { CellModel } from "./cellModel";
3
+ export declare function normalizeCellValidation(cellValidation: CellValidationSource): CellValidation;
4
+ export declare function validateValue(cell: CellModel, newValue: unknown): boolean;
5
+ //# sourceMappingURL=validations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validations.d.ts","sourceRoot":"","sources":["../../src/model/validations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,oBAAoB,GAAG,cAAc,CAK5F;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAczE"}
@@ -0,0 +1,24 @@
1
+ export function normalizeCellValidation(cellValidation) {
2
+ if (cellValidation.pattern && typeof cellValidation.pattern === 'string') {
3
+ cellValidation.pattern = new RegExp(cellValidation.pattern);
4
+ }
5
+ return cellValidation;
6
+ }
7
+ export function validateValue(cell, newValue) {
8
+ const validation = cell.validation;
9
+ if (!validation)
10
+ return true;
11
+ if (validation.allowInvalid)
12
+ return true;
13
+ let valid = true;
14
+ if (validation.pattern) {
15
+ if (!validation.pattern.test((newValue ?? '').toString()))
16
+ valid = false;
17
+ }
18
+ if (validation.validate) {
19
+ if (!validation.validate(cell, newValue))
20
+ valid = false;
21
+ }
22
+ return valid;
23
+ }
24
+ //# sourceMappingURL=validations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validations.js","sourceRoot":"","sources":["../../src/model/validations.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,uBAAuB,CAAC,cAAoC;IAC3E,IAAI,cAAc,CAAC,OAAO,IAAI,OAAO,cAAc,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC1E,cAAc,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,cAAgC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAe,EAAE,QAAiB;IAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACnC,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,IAAI,UAAU,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAEzC,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAE,QAAmB,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;YAAE,KAAK,GAAG,KAAK,CAAC;IACtF,CAAC;IAED,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;QACzB,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;YAAE,KAAK,GAAG,KAAK,CAAC;IACzD,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { CellValidation, CellValidationSource } from \"../types\";\nimport { CellModel } from \"./cellModel\";\n\nexport function normalizeCellValidation(cellValidation: CellValidationSource): CellValidation {\n\tif (cellValidation.pattern && typeof cellValidation.pattern === 'string') {\n\t\tcellValidation.pattern = new RegExp(cellValidation.pattern);\n\t}\n\treturn cellValidation as CellValidation;\n}\n\nexport function validateValue(cell: CellModel, newValue: unknown): boolean {\n\tconst validation = cell.validation;\n\tif (!validation) return true;\n\tif (validation.allowInvalid) return true;\n\n\tlet valid = true;\n\tif (validation.pattern) {\n\t\tif (!validation.pattern.test(((newValue as string) ?? '').toString())) valid = false;\n\t}\n\n\tif (validation.validate) {\n\t\tif (!validation.validate(cell, newValue)) valid = false;\n\t}\n\treturn valid;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './sparklines';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sparklines/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './sparklines';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sparklines/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC","sourcesContent":["export * from './sparklines';"]}
@@ -0,0 +1,59 @@
1
+ import { CellAddress, CellRange, RangeAddress } from "../common";
2
+ import { GridModel } from "../model";
3
+ import { DependencyModel } from "../model/dependencyModel";
4
+ import { ShiftOptions } from "../types";
5
+ export type SparklineType = 'line' | 'column';
6
+ export type SparklineExtremeValue = 'auto' | 'common' | number;
7
+ export type SparklineOptions = {
8
+ /** Minimum value of sparkline (absolute value, "auto", "common") */
9
+ minValue: SparklineExtremeValue;
10
+ /** Maximum value of sparkline (bsolute value, "auto", "common") */
11
+ maxValue: SparklineExtremeValue;
12
+ /** Chart type ("line", "column") */
13
+ type: SparklineType;
14
+ style: {
15
+ color: string;
16
+ weight: number;
17
+ };
18
+ marker?: {
19
+ color: string;
20
+ };
21
+ };
22
+ /** Source object type for sparkline definition */
23
+ export type SparklineSource = {
24
+ /** Cell range containing sparklines */
25
+ location: RangeAddress;
26
+ /** Cell ranges of sparkline data sources. Array or comma separated string. */
27
+ data: RangeAddress | RangeAddress[];
28
+ /** Sparkline options */
29
+ options?: Partial<SparklineOptions>;
30
+ };
31
+ export type SparklineDataRanges = [CellRange, string?][];
32
+ export type SparklineItem = [number, SparklineDataRanges];
33
+ export type SparklineGroupDef = SparklineOptions & {
34
+ dataRanges: SparklineDataRanges;
35
+ locRange: CellRange;
36
+ };
37
+ export declare class Sparklines extends DependencyModel {
38
+ readonly model: GridModel;
39
+ map: Map<string, SparklineItem>;
40
+ groups: Map<number, SparklineGroupDef>;
41
+ extremes: Map<number, [number, number]>;
42
+ maxIndex: number;
43
+ updateRangeMap: boolean;
44
+ constructor(model: GridModel, sourceData?: SparklineSource[]);
45
+ populate(sourceData: SparklineSource[]): void;
46
+ getSourceData(): SparklineSource[];
47
+ has(address: CellAddress): boolean;
48
+ get(address: CellAddress): SparklineItem;
49
+ createDependencies(address: CellAddress): void;
50
+ updateRangeMaps(): void;
51
+ getValues(address: CellAddress): number[];
52
+ getExtremes(address: CellAddress): [number, number];
53
+ createRangeMap(groupIndex: number, locRange: CellRange, dataRanges: SparklineDataRanges): void;
54
+ add(locRange: CellRange, dataRanges: SparklineDataRanges, options?: SparklineOptions): void;
55
+ update(groupIndex: number, locRange: CellRange, dataRanges: SparklineDataRanges, options?: SparklineOptions): void;
56
+ delete(groupIndex: number): void;
57
+ shift(options: ShiftOptions): void;
58
+ }
59
+ //# sourceMappingURL=sparklines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparklines.d.ts","sourceRoot":"","sources":["../../src/sparklines/sparklines.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,MAAM,aAAa,GAAG,MAAM,GAAC,QAAQ,CAAC;AAC5C,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAC,QAAQ,GAAC,MAAM,CAAC;AAC3D,MAAM,MAAM,gBAAgB,GAAG;IAC9B,oEAAoE;IACpE,QAAQ,EAAE,qBAAqB,CAAC;IAChC,mEAAmE;IACnE,QAAQ,EAAE,qBAAqB,CAAC;IAChC,oCAAoC;IACpC,IAAI,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